Public Function SearchGroup() As ADODB.Recordset Dim oResult As ADODB.Recordset Dim oCommand As ADODB.Command Dim sConnectionStr As String
If m_sAdmin = vbNullString Then sConnectionStr = "Provider=ADsDSOObject" Else sConnectionStr = "Provider=ADsDSOObject;UID=" & m_sAdmin & ";PWD=" & m_sAdminPwd End If
Set oCommand = New ADODB.Command With oCommand .ActiveConnection = sConnectionStr .CommandTimeout = 15 .CommandText = "SELECT name,description FROM ''''LDAP://" & m_sDomain _ & "'''' WHERE objectCategory=''''group''''" Debug.Print .CommandText .Properties("searchscope") = ADS_SCOPE_SUBTREE .Properties("Chase referrals") = ADS_CHASE_REFERRALS_EXTERNAL Set oResult = .Execute End With If Not oResult Is Nothing Then Do Until oResult.EOF Debug.Print oResult("name"), oResult("description")(0) oResult.MoveNext Loop End If End Function
PS:很久以前写的东西,望指正。