考虑在 Active Directory 中为用户设置的以下属性:
在我的 winforms 应用程序中,我想显示当前登录并使用该应用程序的用户的显示名称。我将如何检索这些信息?
最佳答案
由于您使用的是 .NET 4,因此可以使用 System.DirectoryServices.AccountManagement
(S.DS.AM) 命名空间。在这里阅读所有相关信息:
- Managing Directory Security Principals in the .NET Framework 3.5
- MSDN docs on System.DirectoryServices.AccountManagement
基本上,您可以定义域上下文并在 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 中与用户和组互动变得非常容易。
关于c# - 如何获取当前登录用户的广告显示名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6692767/