C#のプログラムは、管理者として実行されているかどうかを判断します

コード:

パブリック 静的ブールIsAdministrator(){ 
      System.Security.Principal.WindowsIdentityアイデンティティ = System.Security.Principal.WindowsIdentity.GetCurrent()。
      System.Security.Principal.WindowsPrincipal校長 = 新しいSystem.Security.Principal.WindowsPrincipal(アイデンティティ)。
      リターンprincipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)。
}

 

参考:

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

おすすめ

転載: www.cnblogs.com/tommy-huang/p/12469381.html