Guest User

Untitled

a guest
Jul 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
  2. bool administrativeMode = principal.IsInRole(WindowsBuiltInRole.Administrator);
  3.  
  4. if (!administrativeMode) {
  5. ProcessStartInfo startInfo = new ProcessStartInfo();
  6. startInfo.Verb = "runas";
  7. startInfo.FileName = Assembly.GetExecutingAssembly().CodeBase;
  8. try {
  9. Process.Start(startInfo);
  10. Application.Exit();
  11. }
  12. catch {
  13. //User denied access
  14. return;
  15. }
  16. return;
  17. }
Add Comment
Please, Sign In to add comment