The following example shows how Automation clients can use ActiveX Data Objects (ADO) to query directory services using ADSI and its OLE DB implementation. The ADO object model consists of the following objects:
For more information, see the Microsoft Platform SDK under ActiveX Data Objects.
The following example disables the user accounts on an ldap server.
Dim X as IADs
Dim con As New Connection, rs As New Recordset
Dim MyUser As IADsUser
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider", "CN=Foobar,CN=Users,DC=MICROSOFT,DC=COM,O=INTERNET", "Password"
Set rs = con.Execute("<LDAP://ldapserver.microsoft.com/O=Internet/DC=COM/DC=MICROSOFT/OU=MyOrg>;(objectClass=User);ADsPath;onelevel")
While Not rs.EOF
MyUser = GetObject(rs.Fields(0).Value)
MyUser.AccountDisabled = True
rs.MoveNext
Wend