惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
量子位
雷峰网
雷峰网
宝玉的分享
宝玉的分享
V
Visual Studio Blog
博客园_首页
小众软件
小众软件
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
S
SegmentFault 最新的问题
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学

博客园 - 源码工作室

什么是公司战略 开通了知识星球圈“程序猿团队管理之道” 我们的双12活动总结 做电商的切身经验分享 Android编译报Errors running builder 'Android Pre Compiler' on project 'XXX' java.lang.NullPointerException 技术不如你,但老板就是赏识他,为什么? 看我是如何快速学习android开发的(一) 屌丝创业,你能闯过这么多关吗? android不能显示log的问题 第一次和风投接触 你体会过创业的艰辛吗? 多个WPF工程公用ResourceDictionary文件 Bambook大赛程序结果发布兼拉票 Bambook大赛程序终于发布了 删除USB转串口的所有驱动 《家庭财务总管》升级(1.0.0.3) MFC中Wizard中看不到类的解决办法 总结C++中的所有强制转换函数(const_cast,reinterpret_cast,static_cast,dynamic_cast)(转载) WPF中template的区别
C# 如何检查当前用户在Windows系统下的权限
源码工作室 · 2010-02-10 · via 博客园 - 源码工作室

Posted on 2010-02-10 11:35  源码工作室  阅读(2459)  评论()    收藏  举报

System.Security.Principal.WindowsIdentity wid = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal printcipal = new System.Security.Principal.WindowsPrincipal(wid);
bool isAdmin=(printcipal .IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator));
如果 isAdmin 为true,则是在管理员权限下。

namespace System.Security.Principal
{
    // Summary:
    //     Specifies common roles to be used with System.Security.Principal.WindowsPrincipal.IsInRole(System.String).
    [Serializable]
    [ComVisible(true)]
    public enum WindowsBuiltInRole
    {
        // Summary:
        //     Administrators have complete and unrestricted access to the computer or domain.
        Administrator = 544,
        //
        // Summary:
        //     Users are prevented from making accidental or intentional system-wide changes.
        //     Thus, users can run certified applications, but not most legacy applications.
        User = 545,
        //
        // Summary:
        //     Guests are more restricted than users.
        Guest = 546,
        //
        // Summary:
        //     Power users possess most administrative permissions with some restrictions.
        //     Thus, power users can run legacy applications, in addition to certified applications.
        PowerUser = 547,
        //
        // Summary:
        //     Account operators manage the user accounts on a computer or domain.
        AccountOperator = 548,
        //
        // Summary:
        //     System operators manage a particular computer.
        SystemOperator = 549,
        //
        // Summary:
        //     Print operators can take control of a printer.
        PrintOperator = 550,
        //
        // Summary:
        //     Backup operators can override security restrictions for the sole purpose
        //     of backing up or restoring files.
        BackupOperator = 551,
        //
        // Summary:
        //     Replicators support file replication in a domain.
        Replicator = 552,
    }
}