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/

posted @ 2020-03-12 15:05  一菲聪天  阅读(828)  评论(0编辑  收藏  举报