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

      

  • 相关阅读:
    体验最火的敏捷——SCRUM(厦门,2014.1.4)
    再谈僵尸大会(每日会议)
    神马是敏捷?(4)——敏捷不能当饭吃
    XMLHttpRequest
    xml基础
    element 更换主题
    css3中新增的背景属性和文本效果
    transform rotate旋转 锯齿的解决办法
    优化实现Mobile/Bumped Diffuse
    优化实现Mobile Diffuse动态直接光照shader
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10299470.html
Copyright © 2011-2022 走看看