C#實現(xiàn)判斷當(dāng)前操作用戶管理角色的方法
更新時間:2015年08月24日 12:46:06 作者:我心依舊
這篇文章主要介紹了C#實現(xiàn)判斷當(dāng)前操作用戶管理角色的方法,涉及C#針對系統(tǒng)用戶判斷的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#實現(xiàn)判斷當(dāng)前操作用戶管理角色的方法。分享給大家供大家參考。具體實現(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("超級用戶"); 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ù)制程序員"); }
希望本文所述對大家的C#程序設(shè)計有所幫助。
您可能感興趣的文章:
- c# 將Minio.exe注冊成windows服務(wù)
- C#用Topshelf創(chuàng)建Windows服務(wù)的步驟分享
- C#開發(fā)windows服務(wù)實現(xiàn)自動從FTP服務(wù)器下載文件
- C#對Windows服務(wù)組的啟動與停止操作
- C#編寫Windows服務(wù)程序詳細(xì)步驟詳解(圖文)
- C# 屏蔽由于崩潰彈出的windows異常彈框
- C#實現(xiàn)的WINDOWS登錄功能示例
- 使用C#創(chuàng)建Windows服務(wù)的實例代碼
- C# WindowsForm程序同時啟動多個窗口類
- 使用C#實現(xiàn)Windows組和用戶管理的示例代碼
相關(guān)文章
C#實現(xiàn)掃描局域網(wǎng)內(nèi)的所有IP和端口
這篇文章主要為大家詳細(xì)介紹了如何利用C#實現(xiàn)掃描局域網(wǎng)內(nèi)的所有IP和端口的功能,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下2022-12-12C#實現(xiàn)通過模板自動創(chuàng)建Word文檔的方法
這篇文章主要介紹了C#實現(xiàn)通過模板自動創(chuàng)建Word文檔的方法,詳細(xì)講述了C#生成Word文檔的實現(xiàn)方法,是非常實用的技巧,需要的朋友可以參考下2014-09-09C#調(diào)用mmpeg進(jìn)行各種視頻轉(zhuǎn)換的類實例
這篇文章主要介紹了C#調(diào)用mmpeg進(jìn)行各種視頻轉(zhuǎn)換的類,實例分析了C#調(diào)用mmpeg操作視頻文件的技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03WinForm實現(xiàn)基于BindingSource的方法擴展
這篇文章主要介紹了WinForm實現(xiàn)基于BindingSource的方法擴展,需要的朋友可以參考下2014-08-08