我如何获得当前登录用户的AD显示名称 [英] How do I get the AD Display Name of the currently logged in user
问题描述
认为是建立在Active Directory用户以下属性:
Consider the following properties as set up in Active Directory for a user:
在我的WinForms应用程序,我想显示在显示名称谁当前登录和使用应用程序的用户的。我怎么会去获取这些信息?
In my winforms application I would like to show the Display Name of the user who is currently logged on and using the application. How would I go about retrieving this information?
推荐答案
既然你是在.NET 4中,你可以使用 System.DirectoryServices.AccountManagement
(S .DS.AM)命名空间。阅读所有关于它的:
Since you're on .NET 4, you can use the System.DirectoryServices.AccountManagement
(S.DS.AM) namespace. Read all about it here:
- Managing Directory Security Principals in the .NET Framework 3.5
- MSDN docs on System.DirectoryServices.AccountManagement
基本上,你可以定义域范围内,并很容易地找到在AD用户和/或组:
Basically, you can define a domain context and easily find users and/or groups in AD:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find currently logged in user
UserPrincipal user = UserPrincipal.Current;
string displayName = user.DisplayName;
新S.DS.AM使得它可以很容易地玩弄用户和组AD。
The new S.DS.AM makes it really easy to play around with users and groups in AD.
这篇关于我如何获得当前登录用户的AD显示名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!