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 += "当前用户为来宾用户
    ";
            }
    

      

  • 相关阅读:
    tcp/ip基础
    Fiddler进行模拟Post提交json数据,总为null解决方式(转)
    mysql function动态执行不同sql语句
    SQL语句中各个部分的执行顺序(转)
    shell的初步介绍
    linux分区
    转00600异常解决方案:ORA-00600: 内部错误代码, 参数: [19004], [], [], [], [], []
    一小时执行一次存储过程
    Oracle中的job的定时任务
    Oracle 存储过程错误之PLS-00201: 必须声明标识符
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10299470.html
Copyright © 2011-2022 走看看