mirror of
https://github.com/ckaczor/Common.git
synced 2026-02-16 10:58:34 -05:00
Add ability to relaunch as admin
This commit is contained in:
@@ -141,6 +141,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DateTimeExtensions.cs" />
|
<Compile Include="DateTimeExtensions.cs" />
|
||||||
|
<Compile Include="Security.cs" />
|
||||||
<Compile Include="Trace\BeginEndTracer.cs" />
|
<Compile Include="Trace\BeginEndTracer.cs" />
|
||||||
<Compile Include="Extensions\Extensions.cs" />
|
<Compile Include="Extensions\Extensions.cs" />
|
||||||
<Compile Include="Helpers\ApplicationIsolation.cs" />
|
<Compile Include="Helpers\ApplicationIsolation.cs" />
|
||||||
|
|||||||
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