我在网上有一些关于检索Active Directory域的NetBIOSName(Pre-windows 2000域名)的代码。这是我的代码示例:
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 = crossRef)(systemFlags = 3))”过滤器时,我没有得到任何结果,但是当我删除systemFlags过滤器时,我得到了一些结果。
但是,在我得到的搜索结果中,我仍然无法访问ncName和NetBIOSName属性的值。我可以正确地获得搜索结果的其他属性,如distinguishedName和CN。
关于我可能做错了什么,或者在哪里看得更远的任何想法?
答案 0 :(得分:1)
我找到了一个解决方案,我不知道这是不是正确的,但它确实有效。我从
更改了ADSPath的值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服务器的值。