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