手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#实现判断当前操作用户管理角色的方法
C#实现判断当前操作用户管理角色的方法
摘要:本文实例讲述了C#实现判断当前操作用户管理角色的方法。分享给大家供大家参考。具体实现方法如下://////判断当前操作用户的管理角色///p...

本文实例讲述了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#程序设计有所帮助。

【C#实现判断当前操作用户管理角色的方法】相关文章:

C# 如何判断两个文件内容是否相同的方法

C#对XML文件的各种操作实现方法

C# 获取打印机当前状态的方法

C#使用DllImport调用非托管的代码的方法

c#实现输出本月的月历

用C#对ADO.NET数据库完成简单操作的方法

C#操作config文件的具体方法

C#操作注册表的方法

C#利用com操作excel释放进程的解决方法

C#中判断本地系统的网络连接状态的方法

精品推荐
分类导航