2010-04-15 79 views
0

我在网络上有关检索Active Directory域的NetBIOSName(Pre-windows 2000域名)的一些代码。这里是我的代码示例:无法获得ncName和netBIOSName属性

Me._rootDSE = New System.DirectoryServices.DirectoryEntry("GC://RootDSE", "", "") 
     Dim results As System.DirectoryServices.SearchResultCollection = Nothing 
     Dim ADSPath As String = "GC://CN=Partitions," + Me._rootDSE.Properties("configurationNamingContext").Value.ToString() 

     Dim adse As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry(ADSPath, "", "") 

     Dim searcher As System.DirectoryServices.DirectorySearcher 

     searcher = New System.DirectoryServices.DirectorySearcher(adse) 
     searcher.SearchScope = DirectoryServices.SearchScope.OneLevel 
     searcher.Filter = "(&(objectClass=crossRef)(systemflags=3))" 
     searcher.PropertiesToLoad.Add("netbiosname") 
     searcher.PropertiesToLoad.Add("ncname") 

     results = searcher.FindAll() 

     If results.Count > 0 Then 
     For Each sr As System.DirectoryServices.SearchResult In results 
      Dim de As System.DirectoryServices.DirectoryEntry = sr.GetDirectoryEntry() 
      'netbiosname and ncname properties returns nothing 
      System.Diagnostics.Trace.WriteLine(sr.GetDirectoryEntry().Properties("netbiosname").Value.ToString()) 
      System.Diagnostics.Trace.WriteLine(sr.GetDirectoryEntry().Properties("ncname").Value.ToString()) 
     Next 
     End If 

当我使用“(&(objectClass的=交叉引用)(systemFlags = 3))”过滤器,我没有得到任何结果,但是当我删除了systemFlags过滤器,我得到一些结果。

但是,在我得到的搜索结果中,我仍然无法访问ncName和NetBIOSName属性的值。我可以正确地获得其他属性,例如distinguishedName和CN的搜索结果。

任何想法,我可能做错了什么,或在哪里看得更远?

回答

1

我找到了一个解决方案,我不知道这是否是正确的,但它工作。我改变了Active Directory路径的值从

Dim ADSPath As String = "GC://CN=Partitions," + Me._rootDSE.Properties("co.. 

Dim ADSPath As String = "LDAP://<server>/CN=Partitions," + Me._rootDSE.Properties("co.. 

我提供的LDAP服务器地址和一切工作。现在,如果我只能以编程方式获取LDAP服务器的IP地址或FQDN,则不必使用配置文件来存储LDAP服务器的值。

+2

由于您搜索了全局编录(GC://)并且netbiosname属性未存储在此处,所以无法正常工作。 – Amnon 2010-11-08 13:25:33