From dbbe10514a053d09b745721beb9bea054b53d128 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Sat, 19 Jul 2014 08:29:07 -0400 Subject: [PATCH] Add ability to relaunch as admin --- Common.csproj | 1 + Security.cs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Security.cs 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); + } + } + } +}