【问题标题】:Unable to get ncName and netBIOSName Properties无法获取 ncName 和 netBIOSName 属性
【发布时间】:2010-04-15 08:17:58
【问题描述】:

我在网上有一些关于检索 Active Directory 域的 NetBIOSName(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 属性的值。我可以正确获取搜索结果的 distinctName 和 CN 等其他属性。

知道我可能做错了什么,或者在哪里可以进一步查看?

【问题讨论】:

    标签: vb.net active-directory ldap


    【解决方案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 服务器的值了。

    【讨论】:

    • 它不起作用,因为您搜索了全局目录 (GC://),但 netbiosname 属性没有存储在那里。
    猜你喜欢
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多