如何检查我的应用程序是否以管理员权限启动?我现在使用这段代码:
public static bool IsUserAdministrator()
{
//bool value to hold our return value
bool isAdmin;
try
{
//get the currently logged in user
WindowsIdentity user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch (UnauthorizedAccessException ex)
{
isAdmin = false;
}
catch (Exception ex)
{
isAdmin = false;
}
return isAdmin;
}
此代码检查用户权限,我需要检查应用程序拥有的权限。例如,我不是管理员,但是当应用程序以管理员权限启动时,此代码返回 false。谢谢!