Unable to get ncName and netBIOSName Properties
- by Randz
I've some code on the net regarding retrieval of NetBIOSName (Pre-windows 2000 domain name) of an Active Directory Domain. Here's my code sample:
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
When I am using the "(&(objectClass=crossRef)(systemFlags=3))" filter, I am not getting any result, but when I removed the systemFlags filter, I get some results.
However, on the search results that I got, I still cannot access the values of ncName and NetBIOSName properties. I can get other properties like distinguishedName and CN of the search result properly.
Any idea on what I might be doing wrong, or where to look further?