mirror of
https://github.com/ckaczor/Common.git
synced 2026-01-14 17:22:51 -05:00
35 lines
920 B
C#
35 lines
920 B
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|