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的搜索结果。
任何想法,我可能做错了什么,或在哪里看得更远?
由于您搜索了全局编录(GC://)并且netbiosname属性未存储在此处,所以无法正常工作。 – Amnon 2010-11-08 13:25:33