From b614edecdbe31fedf2f886424475b3e058c52b6e Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 10 Oct 2021 13:06:43 +1000 Subject: [PATCH] Detect when running as Superuser/Administrator not using this for anything atm --- src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs | 5 +++++ src/BizHawk.Client.EmuHawk/Program.cs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs b/src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs index 04585374a5..2e9c6088ec 100644 --- a/src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs +++ b/src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs @@ -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 { + /// iff running as Administrator (on Windows) or Superuser (on Unix under Mono) + /// TODO check .NET Core + public static readonly bool CLRHostHasElevatedPrivileges = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); + /// http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp public static string ResolveShortcut(string filename) { diff --git a/src/BizHawk.Client.EmuHawk/Program.cs b/src/BizHawk.Client.EmuHawk/Program.cs index 3def9e92c9..b828c1acae 100644 --- a/src/BizHawk.Client.EmuHawk/Program.cs +++ b/src/BizHawk.Client.EmuHawk/Program.cs @@ -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 {