开发者

Unable to get ncName and netBIOSName Properties

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 开发者_JAVA技巧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?


I found a solution, I don't know if this is the correct one but it is working. I changed the value of ADSPath from

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

to

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

I supplied the LDAP server address to and everything worked out. Now, if only I could get the IP address or FQDN of the LDAP Server programmatically, I won't have to use config file to store the value of LDAP Server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜