Detect when running as Superuser/Administrator

not using this for anything atm
This commit is contained in:
YoshiRulz 2021-10-10 13:06:43 +10:00
parent 8145dfbdce
commit b614edecdb
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 7 additions and 0 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Security.Principal;
using System.Text;
using BizHawk.Common;
@ -7,6 +8,10 @@ namespace BizHawk.Client.EmuHawk
{
public static class EmuHawkUtil
{
/// <summary><see langword="true"/> iff running as Administrator (on Windows) or Superuser (on Unix under Mono)</summary>
/// <remarks>TODO check .NET Core</remarks>
public static readonly bool CLRHostHasElevatedPrivileges = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
/// <remarks>http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp</remarks>
public static string ResolveShortcut(string filename)
{

View File

@ -219,6 +219,8 @@ namespace BizHawk.Client.EmuHawk
SetDllDirectory(dllDir);
}
Util.DebugWriteLine(EmuHawkUtil.CLRHostHasElevatedPrivileges ? "running as Superuser/Administrator" : "running as unprivileged user");
var exitCode = 0;
try
{