public bool IsAdministrator() { WindowsIdentity current = WindowsIdentity.GetCurrent(); WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current); return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator); }
转载声明:本文转载至http://www.zhoumy.cn/?id=4
本文分享了一段使用C#编写的代码,用于检查当前运行应用程序的用户是否具有管理员权限。通过WindowsIdentity和WindowsPrincipal类,代码可以判断用户是否属于内置的管理员角色。
3万+

被折叠的 条评论
为什么被折叠?



