C# 之 判断或设置以管理员身份运行程序 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);
}

  一、判断程序是否以管理员权限运行

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);
}

猜你喜欢

转载自www.cnblogs.com/gisoracle/p/10386036.html