Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
- bool administrativeMode = principal.IsInRole(WindowsBuiltInRole.Administrator);
- if (!administrativeMode) {
- ProcessStartInfo startInfo = new ProcessStartInfo();
- startInfo.Verb = "runas";
- startInfo.FileName = Assembly.GetExecutingAssembly().CodeBase;
- try {
- Process.Start(startInfo);
- Application.Exit();
- }
- catch {
- //User denied access
- return;
- }
- return;
- }
Add Comment
Please, Sign In to add comment