C# 获取广告计算机&x27;s描述

C# 获取广告计算机&x27;s描述,c#,visual-studio-2010,active-directory,C#,Visual Studio 2010,Active Directory,我需要得到域计算机的描述。从注册表我只能得到本地描述,但我需要Active Directory描述。有什么想法吗 向前看! 谢谢大家! 使用DirectoryEntry类(System.DirectoryServices命名空间)来 连接到Active Directory。提供用户名和密码以及LDAP根路径 在Active Directory中搜索计算机对象。然后使用DirectorySearcher 类来查询计算机对象 下面的代码显示了如何搜索名为computer01的计算机。 我还将desc

我需要得到域计算机的描述。从注册表我只能得到本地描述,但我需要Active Directory描述。有什么想法吗

向前看!
谢谢大家!

使用
DirectoryEntry
类(
System.DirectoryServices
命名空间)来 连接到Active Directory。提供用户名和密码以及LDAP根路径 在Active Directory中搜索计算机对象。然后使用
DirectorySearcher
类来查询计算机对象

下面的代码显示了如何搜索名为computer01的计算机。 我还将description属性添加到要加载的属性中 (默认情况下,并非所有属性都会加载)。在下面的代码中,您必须替换 使用域控制器的名称。以同样的方式替换标签 使用您的域名。例如,如果Active Directory服务器的名称为 server01,域名为fabrikam.com,则LDAP路径为
LDAP://server01/dc=fabrikam,dc=com

using (DirectoryEntry entry = new DirectoryEntry("LDAP://<your-ad-server-name>/dc=<domain-name-part>,dc=<domain-name-part>",
     "Administrator", "Your Secure Password", AuthenticationTypes.Secure))
{
  using (DirectorySearcher adSearcher = new DirectorySearcher(entry))
  {
    string computerName = "computer01";
    adSearcher.Filter = "(&(objectClass=computer)(cn=" + computerName + "))";
    adSearcher.SearchScope = SearchScope.Subtree;
    adSearcher.PropertiesToLoad.Add("description");
    SearchResult searchResult = adSearcher.FindOne();

    Console.Out.WriteLine(searchResult.GetDirectoryEntry().Properties["description"].Value);
  }
}
使用(DirectoryEntry=newdirectoryentry(“LDAP:///dc=,dc=”,
“管理员”、“您的安全密码”、AuthenticationTypes.Secure)
{
使用(DirectorySearcher adSearcher=新的DirectorySearcher(条目))
{
字符串computerName=“computer01”;
adSearcher.Filter=“(&(objectClass=computer)(cn=“+computerName+”)”);
adSearcher.SearchScope=SearchScope.Subtree;
adSearcher.PropertiesToLoad.Add(“说明”);
SearchResult SearchResult=adSearcher.FindOne();
Console.Out.WriteLine(searchResult.GetDirectoryEntry().Properties[“description”].Value);
}
}
请注意,上面的代码在整个Active Directory中搜索计算机对象。 要仅在Computers容器中搜索,请使用以下LDAP路径:

LDAP://<your-ad-server-name>/cn=Computers,dc=<domain-name-part>,dc=<domain-name-part>
LDAP:///cn=Computers,dc=,dc=

使用System.DirectoryServices联系您的广告并询问他:)找不到正确的使用方法..:(你不知道吗?不是在广告环境中,所以不能测试任何东西。看看