C#實(shí)現(xiàn)判斷當(dāng)前操作用戶管理角色的方法
更新時(shí)間:2015年08月24日 12:46:06 作者:我心依舊
這篇文章主要介紹了C#實(shí)現(xiàn)判斷當(dāng)前操作用戶管理角色的方法,涉及C#針對(duì)系統(tǒng)用戶判斷的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#實(shí)現(xiàn)判斷當(dāng)前操作用戶管理角色的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
/// <summary>
/// 判斷當(dāng)前操作用戶的管理角色
/// </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("當(dāng)前用戶的角色是:");
if (IsUser)
Console.WriteLine("來(lái)賓");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.User);
if (IsUser)
Console.WriteLine("普通用戶");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.PowerUser);
if (IsUser)
Console.WriteLine("超級(jí)用戶");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
if (IsUser)
Console.WriteLine("系統(tǒng)管理員");
IsUser = wp.IsInRole(System.Security.Principal.WindowsBuiltInRole.SystemOperator);
if (IsUser)
Console.WriteLine("系統(tǒng)操作員");
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("復(fù)制程序員");
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- c# 將Minio.exe注冊(cè)成windows服務(wù)
- C#用Topshelf創(chuàng)建Windows服務(wù)的步驟分享
- C#開發(fā)windows服務(wù)實(shí)現(xiàn)自動(dòng)從FTP服務(wù)器下載文件
- C#對(duì)Windows服務(wù)組的啟動(dòng)與停止操作
- C#編寫Windows服務(wù)程序詳細(xì)步驟詳解(圖文)
- C# 屏蔽由于崩潰彈出的windows異常彈框
- C#實(shí)現(xiàn)的WINDOWS登錄功能示例
- 使用C#創(chuàng)建Windows服務(wù)的實(shí)例代碼
- C# WindowsForm程序同時(shí)啟動(dòng)多個(gè)窗口類
- 使用C#實(shí)現(xiàn)Windows組和用戶管理的示例代碼
相關(guān)文章
C#.NET中如何批量插入大量數(shù)據(jù)到數(shù)據(jù)庫(kù)中
這篇文章主要給大家介紹C#.net中如何批量插入大量數(shù)據(jù)到數(shù)據(jù)庫(kù)中,本文涉及到C#.net中批量插入數(shù)據(jù)到數(shù)據(jù)庫(kù)中方面的內(nèi)容,對(duì)C#.net批量插入數(shù)據(jù)到數(shù)據(jù)庫(kù)中感興趣的朋友可以參考下本篇文章2015-10-10
Unity OnGUI實(shí)時(shí)顯示游戲FPS
這篇文章主要為大家詳細(xì)介紹了Unity OnGUI實(shí)時(shí)顯示游戲FPS,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11
C#獲取串口列表實(shí)現(xiàn)實(shí)時(shí)監(jiān)控串口
本文主要介紹兩種獲取串口列表的方法,比較簡(jiǎn)單,方便大家使用,另外分享了一個(gè)已封裝的API,需要的朋友可以參考下。2016-05-05
C#設(shè)計(jì)模式之Facade外觀模式解決天河城購(gòu)物問(wèn)題示例
這篇文章主要介紹了C#設(shè)計(jì)模式之Facade外觀模式解決天河城購(gòu)物問(wèn)題,簡(jiǎn)單描述了外觀模式的定義并結(jié)合具體實(shí)例分析了外觀模式解決購(gòu)物問(wèn)題的相關(guān)步驟與操作技巧,需要的朋友可以參考下2017-09-09

