From 03bf5387a72bf92caf53216fe60aa649da848f5b Mon Sep 17 00:00:00 2001 From: Elivo Date: Tue, 27 May 2025 01:29:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20IsAdministratorRole=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apewer/RuntimeUtility.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Apewer/RuntimeUtility.cs b/Apewer/RuntimeUtility.cs index 70be790..da07d3d 100644 --- a/Apewer/RuntimeUtility.cs +++ b/Apewer/RuntimeUtility.cs @@ -1,14 +1,15 @@ using Apewer.Internals; using Apewer.Models; using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; -using System.Threading; -using System.Collections; using System.Text; +using System.Threading; +using static System.Net.Mime.MediaTypeNames; namespace Apewer { @@ -1035,6 +1036,20 @@ namespace Apewer #endif } +#if NETFRAMEWORK + + /// 当前进程是以管理员身份运行。 + public static bool IsAdministratorRole() + { + var identity = System.Security.Principal.WindowsIdentity.GetCurrent(); + var principal = new System.Security.Principal.WindowsPrincipal(identity); + + var result = principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator); + return result; + } + +#endif + #endregion #region Exception