mirror of
https://github.com/ckaczor/Common.git
synced 2026-01-14 01:25:43 -05:00
Add ability to relaunch as admin
This commit is contained in:
34
Security.cs
Normal file
34
Security.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user