feat: Added property to ProgramUtils to determine if the application is running as admin

This commit is contained in:
Chris Cameron
2021-03-02 11:44:36 -05:00
parent b83fba337f
commit 766e2da4e3
2 changed files with 16 additions and 3 deletions

View File

@@ -32,8 +32,6 @@
<None Remove="binNetCoreApp\**" /> <None Remove="binNetCoreApp\**" />
<None Remove="SIMPLSharpLogs\**" /> <None Remove="SIMPLSharpLogs\**" />
</ItemGroup> </ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Remove="ICD.Common.projectinfo" /> <None Remove="ICD.Common.projectinfo" />
<None Remove="ICD.Common_SimplSharp.suo" /> <None Remove="ICD.Common_SimplSharp.suo" />
@@ -47,6 +45,7 @@
<PackageReference Include="Pastel" Version="2.1.0" /> <PackageReference Include="Pastel" Version="2.1.0" />
<PackageReference Include="System.Net.NetworkInformation" Version="4.3.0" /> <PackageReference Include="System.Net.NetworkInformation" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" /> <PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="CultureInfo.sqlite"> <None Update="CultureInfo.sqlite">

View File

@@ -2,6 +2,7 @@
using ICD.Common.Utils.IO; using ICD.Common.Utils.IO;
using System; using System;
using System.Reflection; using System.Reflection;
using System.Security.Principal;
using ICD.Common.Properties; using ICD.Common.Properties;
namespace ICD.Common.Utils namespace ICD.Common.Utils
@@ -64,6 +65,19 @@ namespace ICD.Common.Utils
{ {
get { return IcdFile.GetCreationTime(PathUtils.Join(PathUtils.ProgramPath, ProgramFile)); } get { return IcdFile.GetCreationTime(PathUtils.Join(PathUtils.ProgramPath, ProgramFile)); }
} }
}
/// <summary>
/// Returns true if the current executing user is an admin.
/// </summary>
[PublicAPI]
public static bool IsElevated
{
get
{
WindowsIdentity current = WindowsIdentity.GetCurrent();
return new WindowsPrincipal(current).IsInRole(WindowsBuiltInRole.Administrator);
}
}
}
} }
#endif #endif