-
Notifications
You must be signed in to change notification settings - Fork 0
/
Security.cs
34 lines (29 loc) · 920 Bytes
/
Security.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
}
}
}
}