diff --git a/Common.csproj b/Common.csproj index 598d8a3..3105585 100644 --- a/Common.csproj +++ b/Common.csproj @@ -141,6 +141,7 @@ + diff --git a/Security.cs b/Security.cs new file mode 100644 index 0000000..0579fa2 --- /dev/null +++ b/Security.cs @@ -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); + } + } + } +}