zoukankan      html  css  js  c++  java
  • 判断当前用户的权限

    实现效果:

      

    知识运用:

      WindowsPrincipal类的IsInRole方法    //确定当前主体是否属于制定的Windows用户组

      public virtual bool IsInRole (WindowsBuiltInRole role)    //属性为枚举值之一

      

    实现代码:

            private void button1_Click(object sender, EventArgs e)
            {
                AppDomain domain = System.Threading.Thread.GetDomain();     //获取当前域
                domain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);//将操作系统组映射到角色
                //获取当前系统组
                System.Security.Principal.WindowsPrincipal principal = (System.Security.Principal.WindowsPrincipal)System.Threading.Thread.CurrentPrincipal;
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.User))
                    label1.Text += "当前用户为普通用户
    ";
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.PowerUser))
                    label1.Text += "当前用户为超级用户
    ";
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
                    label1.Text += "当前用户为系统管理员
    ";
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.SystemOperator))
                    label1.Text += "当前用户为系统操作员
    ";
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.BackupOperator))
                    label1.Text += "当前用户为备份操作员
    ";
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.PrintOperator))
                    label1.Text += "当前用户为打印操作员
    ";
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Replicator))
                    label1.Text += "当前用户为复制操作员
    ";
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.AccountOperator))
                    label1.Text += "当前用户为账户操作员
    ";
                if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Guest))
                    label1.Text += "当前用户为来宾用户
    ";
            }
    

      

  • 相关阅读:
    css--display详解
    关于overflow:hidden的作用
    float 应用
    flex 布局
    CSS+DIV布局中absolute和relative的区别
    线程和进程的区别是什么?
    .NET中读写SQL Server数据库需要用到哪些类?作用是什么?
    C# CookieHelper
    git pull/push代码 每次都要输入账户名和密码的解决方法
    git拉取远程分支到本地
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10299470.html
Copyright © 2011-2022 走看看