C#实现判断当前操作用户管理角色的方法
作者:我心依旧 发布时间:2023-06-25 09:48:36
标签:C#,判断,用户
本文实例讲述了C#实现判断当前操作用户管理角色的方法。分享给大家供大家参考。具体实现方法如下:
/// <summary>
/// 判断当前操作用户的管理角色
/// </summary>
public static void GetCurrentUserRole()
{
AppDomain appDomain = System.Threading.Thread.GetDomain();
appDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
System.Security.Principal.WindowsPrincipal wp = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
bool IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.Guest);
Console.Write("当前用户的角色是:");
if (IsUser)
Console.WriteLine("来宾");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.User);
if (IsUser)
Console.WriteLine("普通用户");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.PowerUser);
if (IsUser)
Console.WriteLine("超级用户");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
if (IsUser)
Console.WriteLine("系统管理员");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.SystemOperator);
if (IsUser)
Console.WriteLine("系统操作员");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.BackupOperator);
if (IsUser)
Console.WriteLine("备份操作员");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.PrintOperator);
if (IsUser)
Console.WriteLine("打印操作员");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.AccountOperator);
if (IsUser)
Console.WriteLine("账户操作员");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.Replicator);
if (IsUser)
Console.WriteLine("复制程序员");
}
希望本文所述对大家的C#程序设计有所帮助。


猜你喜欢
- 数据导出到Excel几乎是所有客户都会提出的一个需求。下面我就分享一下我的代码。首先需要引入的jar包:然后就是正式代码了。package
- 本文实例讲述了Android自定义个性化的Dialog。分享给大家供大家参考,具体如下:Dialog:mDialog = new Dialo
- 在android开发中,一说起线程的使用,很多人马上想到new Thread(){...}.start()这种方式。这样使用当然可以,但是多
- #include<iostream>#include<assert.h>#include<stack>#
- 目录1、Java Application 源程序的主类是指包含有( )方法的类。2、如果定义一种表达式结构:(+ 6 3)的值为9,(- 6
- 最近在做学校的课程设计,java编程需要用到对话框弹出,第一反应是js中的alert和confirm,java的话瞬间懵,查阅学习总结如下,
- 在我们对程序进行操作过程中,一般都需要有一个操作流程的记录显示。用C#进行编程时可以很容易实现这个功能。本经验提供案例仅供参考下面小编就来介
- 初学C++的朋友经常在类中看到public,protected,private以及它们在继承中表示的一些访问范围,很容易搞糊涂。今天本文就来
- 最近在玩3g体育门户客户端的时候,看到这样个效果: 轻触赛事图标,会有一个图标变大浮出的效果.,蛮有意思的.于是就把仿照它做了一
- 这篇文章主要介绍了break在scala和java中的区别解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,
- 一、前言做新应用就是这样,会遇到各种问题,昨天刚解决了加载某一个类时候抛出了 class is not visible from class
- 单例模式有一下特点:1、单例类只能有一个实例。2、单例类必须自己自己创建自己的唯一实例。3、单例类必须给所有其他对象提供这一实例。单例模式确
- 有时候,我们使用AOP来进行放的增强,编写切面类的时候,需要定位在哪个方法上试用该切面进行增强,本片文章主要讲解两种在SpringBoot中
- 本文项目为大家分享了Java实现 * 面五子棋的具体代码,供大家参考,具体内容如下项目介绍:本次设计是基于知识点Java类和对象以及数组开发的
- C语言求三次方根前话说到C语言求根,我们一般会想到用sqrt(x)函数,它的输入值和返回值都是double型,x取整将会导致编译器错误。但是
- 本文实例讲述了用WebBrowser操作frame和iframe的方法,比较适合C#初学者参考学习。示例浅显易懂,具体方法如下:
- 前言在介绍Dubbo之前先了解一下基本概念:Dubbo是一个RPC框架,RPC,即Remote Procedure Call(远程过程调用)
- hadoop做的一个简单grep程序,可从文档中提取包含某些字符串的行/* * 一个简单grep程序,可从文档中提取包含莫些字符串
- 对于springboot应用,需要以下几个步骤springboot应用开启endpoint,添加actuator的以来和promethus的
- 之前碰到个问题,使用webview的时候无法定位,最近19大没法墙,只能去百度逛逛,发现有人说要这么做 WebSe