zoukankan      html  css  js  c++  java
  • C# 如何检查当前用户在Windows系统下的权限

    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,
        }
    }

  • 相关阅读:
    好消息:Dubbo & Spring Boot要来了
    过年回家,程序猿最怕的5件事
    到底什么是分布式系统?
    SLA服务可用性4个9是什么意思?怎么达到?
    漏洞:会话固定攻击(session fixation attack)
    Mybatis传递多个参数的4种方式(干货)
    注意:阿里Druid连接池监控的两个坑
    消息中间件ActiveMQ、RabbitMQ、RocketMQ、ZeroMQ、Kafka如何选型?
    Java程序员必须掌握的常用Linux命令。
    编程词汇
  • 原文地址:https://www.cnblogs.com/goodcandle/p/1667012.html
Copyright © 2011-2022 走看看