C# 之 判断或设置以管理员身份运行程序
C# 之 判断或设置以管理员身份运行程序
一、判断程序是否以管理员权限运行
|
1
2
3
4
5
6
7
|
using System.Security.Principal;public bool IsAdministrator(){ WindowsIdentity current = WindowsIdentity.GetCurrent(); WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current); return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);} |
浙公网安备 33010602011771号