哪里是在UserPrincipal对象的域名? [英] Where is the domain name in a UserPrincipal object?

查看:251
本文介绍了哪里是在UserPrincipal对象的域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 System.DirectoryServices.ActiveDirectory 班找到所有Active Directory用户。在code是很简单的:

I'm using the System.DirectoryServices.ActiveDirectory classes to find all Active Directory users. The code is very simple:

var context = new PrincipalContext(ContextType.Domain);
var searcher = new PrincipalSearcher(new UserPrincipal(context));
var results = searcher.FindAll();

我想在友好(又名pre-Windows 2000的格式)的域限定用户名,例如。 CONTOSO \ SmithJ。 UserPrincipal.SamAccountName 给我的用户名的一部分,但我怎么域的一部分?我不能假设的领域将是一样的机器或当前用户的域。

I want to get the domain-qualified username in the "friendly" (aka. "pre-Windows 2000" format), eg. "CONTOSO\SmithJ". UserPrincipal.SamAccountName gives me the username part, but how do I get the domain part? I cannot assume that the domain will be the same as the machine's or current user's domain.

推荐答案

有关AD DS,的msDS-生成PrincipalName 的值是NetBIOS域名,后面跟着一个反斜杠(\)。

For AD DS, the value of msDS-PrincipalName is the NetBIOS domain name, followed by a backslash ("\").

您可以找到它使用:

/* Retreiving the root domain attributes
 */ 
sFromWhere = "LDAP://DC_DNS_NAME:389/dc=dom,dc=fr"; 
DirectoryEntry deBase = new DirectoryEntry(sFromWhere, "AdminLogin", "PWD"); 

DirectorySearcher dsLookForDomain = new DirectorySearcher(deBase); 
dsLookForDomain.Filter = "(objectClass=*)"; 
dsLookForDomain.SearchScope = SearchScope.base; 
dsLookForDomain.PropertiesToLoad.Add("msDS-PrincipalName"); 

SearchResult srcDomains = dsLookForDomain.FindOne();

这篇关于哪里是在UserPrincipal对象的域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆