使用VB6,是否可以获取活动目录中所有可用域的列表?
谢谢, 亚历
答案 0 :(得分:1)
将ActiveDS类型库和ADO的引用添加到项目中。
Sub GetDomains() Dim objRootDSE As IADs Dim objBase As IADs Dim path As String Dim rsDomains As ADODB.Recordset Dim cnADS As ADODB.Connection Dim cmdCommand As ADODB.Command Set objRootDSE = GetObject("LDAP://rootDSE") path = "LDAP://" & objRootDSE.Get("rootDomainNamingContext") Set objBase = GetObject(path) Set cnADS = New ADODB.Connection cnADS.Provider = "ADsDSOObject" cnADS.Open "ADSI" Set cmdCommand = New ADODB.Command cmdCommand.ActiveConnection = cnADS cmdCommand.Properties("searchScope") = ADS_SCOPE_SUBTREE cmdCommand.CommandText = "SELECT Name, distinguishedName FROM '" & objBase.ADsPath & "' WHERE objectCategory = 'domain'" Set rsDomains = cmdCommand.Execute Do While rsDomains.EOF = False List1.AddItem (rsDomains!Name) rsDomains.MoveNext Loop End Sub
我只有一个域可以对此进行测试,所以我希望您需要知道它是否为您提供了所有域名。另请注意,我没有添加错误处理。