如何在窗口7中获取帐户类型,即admin或user [英] How to get account type i.e admin or user in window 7
本文介绍了如何在窗口7中获取帐户类型,即admin或user的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友
有谁能告诉我如何获取用户帐户类型即假设ABC帐户已登录
并且我想检查它是否具有管理权限.
我该怎么做?
Hello friends
Can any tell me how can i get user account type i.e suppose , Account ABC has logon
and I want to check if it has administrative Rights or not.
How can i do this ?
推荐答案
我找到了此代码,如果用户是admin,则返回true,否则返回false
在使用之前,添加Refrence System.DirectoryServices.AccountManagement
I Found this Code , It returns true If User is admin else false
befor using it add Refrence System.DirectoryServices.AccountManagement
public bool IsAdmin ()
{
try
{
var userCurrent = System.DirectoryServices.AccountManagement.UserPrincipal.Current;
var Groups = userCurrent.GetAuthorizationGroups();
var IsPotentialAdmin = Groups.Any(p => p.Sid == new SecurityIdentifier("S-1-5-32-544"));
return IsPotentialAdmin;
}
catch (Exception ex)
{
// this will cause access denied if user is not admin or in "Pre-Windows 2000 combatiblity" group
return false;
}
}
这篇关于如何在窗口7中获取帐户类型,即admin或user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文