Reputation: 5129
I'm trying to write a script that connects to Active Directory using Administrator credentials. Then searches the entire domain for a specific username, then updates that user's properties. I've written a script that I think should work, but I'm getting "Access Denied" errors, weirdly enough.
Here's the script, which I've put into sections. Because it's supposed to run through SuperOffice, which has it's own unique environment.
Dim strUser, rootDSE, adoConnection, ldapStr, adoRecord, objUser
updateUser()
Public Sub updateUser()
ADUsername = "john.doe"
createADConnection()
If userExistsInAD(ADUsername) = False Then
Exit Sub
End if
objUser.Put "description", "testing"
objUser.SetInfo
End Sub
Public Sub createADConnection()
Set rootDSE = GetObject("LDAP://RootDSE")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Properties("User ID") = "mydomain\administrator"
adoConnection.Properties("Password") = "8g773ggj024g"
adoConnection.Properties("Encrypt Password") = True
adoConnection.Properties("ADSI Flag") = ADS_SERVER_BIND Or ADS_SECURE_AUTHENTICATION
adoConnection.Open "Active Directory Provider"
End Sub
Public Function userExistsInAD(ByVal strUser)
ldapStr = "<LDAP://" & rootDSE.Get("defaultNamingContext") & ">;(&(objectCategory=Person)(objectClass=User)(samAccountName=" & strUser & "));adspath;subtree"
Set adoRecord = adoConnection.Execute(ldapStr)
If Not adoRecord.EOF Then
userExistsInAD = True
Exit Function
End if
userExistsInAD = False
End Function
Upvotes: 0
Views: 2404
Reputation: 26
Sounds to me like the account you are running SuperOffice with does not have Domain Admin credentials. Have you tried running it directly with your account?
Upvotes: 1