Add ability to relaunch as admin

This commit is contained in:
2014-07-19 08:29:07 -04:00
parent 5bf33eed83
commit dbbe10514a
2 changed files with 35 additions and 0 deletions

34
Security.cs Normal file
View File

@@ -0,0 +1,34 @@
using System;
using System.Diagnostics;
using System.Security.Principal;
namespace Common
{
public class Security
{
public static void EnsureElevatedInstall()
{
using (var wi = WindowsIdentity.GetCurrent())
{
if (wi == null)
return;
var wp = new WindowsPrincipal(wi);
if (wp.IsInRole(WindowsBuiltInRole.Administrator))
return;
using (var currentProc = Process.GetCurrentProcess())
using (var proc = new Process())
{
proc.StartInfo.Verb = "runas";
proc.StartInfo.FileName = currentProc.MainModule.FileName;
proc.StartInfo.Arguments = "/reinstall";
proc.Start();
}
Environment.Exit(0);
}
}
}
}