code_junkie

Running as admin some times

Nov 12th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. private void elevateCurrentProcess()
  2. {
  3. ProcessStartInfo startInfo = new ProcessStartInfo();
  4. startInfo.UseShellExecute = true;
  5. startInfo.WorkingDirectory = Environment.CurrentDirectory;
  6. startInfo.FileName = Application.ExecutablePath;
  7. startInfo.Verb = "runas";
  8.  
  9. try
  10. {
  11. Process p = Process.Start(startInfo);
  12. }
  13. catch
  14. {
  15. // User didn't allow UAC
  16. return;
  17. }
  18. Application.Exit();
  19. }
Add Comment
Please, Sign In to add comment