如何获取当前登录用户的 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:
基本上,您可以定义域上下文并轻松找到 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屋!