C# 判断程序是否已管理员身份运行

代码:

public static Boolean IsAdministrator() {
      System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
      System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
      return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
}

参考:

https://www.bugfine.com/c/c-sharp-check-whether-in-admin/

原文地址:https://www.cnblogs.com/tommy-huang/p/12469381.html