C#實(shí)現(xiàn)判斷當(dāng)前操作用戶管理角色的方法
本文實(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("來賓"); 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#實(shí)現(xiàn)掃描槍掃描二維碼并打印(實(shí)例代碼)
這篇文章主要介紹了C#實(shí)現(xiàn)掃描槍掃描二維碼并打印,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01C#實(shí)現(xiàn)掃描局域網(wǎng)內(nèi)的所有IP和端口
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)掃描局域網(wǎng)內(nèi)的所有IP和端口的功能,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下2022-12-12C#實(shí)現(xiàn)通過模板自動(dòng)創(chuàng)建Word文檔的方法
這篇文章主要介紹了C#實(shí)現(xiàn)通過模板自動(dòng)創(chuàng)建Word文檔的方法,詳細(xì)講述了C#生成Word文檔的實(shí)現(xiàn)方法,是非常實(shí)用的技巧,需要的朋友可以參考下2014-09-09C#調(diào)用mmpeg進(jìn)行各種視頻轉(zhuǎn)換的類實(shí)例
這篇文章主要介紹了C#調(diào)用mmpeg進(jìn)行各種視頻轉(zhuǎn)換的類,實(shí)例分析了C#調(diào)用mmpeg操作視頻文件的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03深入分析C#鍵盤勾子(Hook)攔截器,屏蔽鍵盤活動(dòng)的詳解
本篇文章是對(duì)C#鍵盤勾子(Hook)攔截器,屏蔽鍵盤活動(dòng)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05WinForm實(shí)現(xiàn)基于BindingSource的方法擴(kuò)展
這篇文章主要介紹了WinForm實(shí)現(xiàn)基于BindingSource的方法擴(kuò)展,需要的朋友可以參考下2014-08-08