strNTName = "abcd" strDNSDomain = "DC=AD,DC=COM" ' Use ADO to search Active Directory. Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Properties("User ID") = "abcd" adoConnection.Properties("Password") = "abcd_wxyz" 'adoConnection.Properties("Encrypt Password") = TRUE 'adoConnection.Properties("ADSI Flag") = 3 'adoConnection.Open adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = adoConnection ' Search entire domain. strBase = "<LDAP://" & strDNSDomain & ">" ' Search for all users. strFilter = "(&(objectCategory=person)(objectClass=user)(samAccountName=" & strNTName & "))" ' Comma delimited list of attribute values to retrieve. 'strAttributes = "givenName,sn,mail,userPrincipalName" strAttributes = "givenName,sn" ' Construct the LDAP query. strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" ' Run the query. adoCommand.CommandText = strQuery adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 30 adoCommand.Properties("Cache Results") = False Set adoRecordset = adoCommand.Execute MsgBox adoRecordset.RecordCount
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)