Skip to content

Commit

Permalink
chore: 启动时检测是否为管理员启动
Browse files Browse the repository at this point in the history
  • Loading branch information
ABA2396 committed Aug 27, 2023
1 parent 0207013 commit e9b22da
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/MaaWpfGui/Main/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Windows;
using System.Windows.Threading;
using GlobalHotKey;
Expand Down Expand Up @@ -106,6 +107,10 @@ protected override void OnStart()
_logger.Information("MaaAssistantArknights GUI started");
_logger.Information("Maa ENV: {MaaEnv}", maaEnv);
_logger.Information("User Dir {CurrentDirectory}", Directory.GetCurrentDirectory());
if (IsUserAdministrator())
{
_logger.Information("Run as Administrator");
}
_logger.Information("===================================");

try
Expand Down Expand Up @@ -134,6 +139,15 @@ protected override void OnStart()
LocalizationHelper.Load();
}

private static bool IsUserAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
SecurityIdentifier adminSid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);

return principal.IsInRole(adminSid);
}

/// <inheritdoc/>
protected override void ConfigureIoC(IStyletIoCBuilder builder)
{
Expand Down

0 comments on commit e9b22da

Please sign in to comment.