amir Posted May 21, 2008 Share Posted May 21, 2008 When i try to execute the code down below, i get :C:\ADT.au3 (22) : ==> The requested action with this object has failed.: Local $objRecordSet = $objCommand.Execute Local $objRecordSet = $objCommand.Execute^ ERRORDoes anyone have any idea why?(i got this code from an old post on the forum)expandcollapse popupLocal $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") $objCommand.ActiveConnection = $objConnection ;Local $strBase = "<GC://dc=YOURDOMAINNAME,dc=COM>" Local $strBase = ObjGet("LDAP//RootDSE") Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties ("Page Size") = 100 $objCommand.Properties ("Timeout") = 30 $objCommand.Properties ("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute ConsoleWrite("Users"&@CR&"---------"&@CR) While Not $objRecordSet.EOF $strName = $objRecordSet.Fields ("sAMAccountName").Value $strCN = $objRecordSet.Fields ("cn").value $strdisplayName = $objRecordSet.Fields ("displayName").value $strSN = $objRecordSet.Fields ("SN").value $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value ;FileWriteLine("Users.txt",$objRecordSet.Fields ("sAMAccountName").Value) ConsoleWrite($objRecordSet.Fields ("sAMAccountName").Value&@cr) $objRecordSet.MoveNext WEnd $objConnection.Close $objConnection = "" $objCommand = "" $objRecordSet = "" Link to comment Share on other sites More sharing options...
amir Posted May 22, 2008 Author Share Posted May 22, 2008 OK, this finally worked for me: The key line for me was: Local $strBase = "<LDAP://dc=YourDOMAINname,dc=DOMAINsuffix>" expandcollapse popupLocal $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<LDAP://dc=YourDOMAINname,dc=DOMAINsuffix>" Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties ("Page Size") = 100 $objCommand.Properties ("Timeout") = 30 $objCommand.Properties ("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE $objRecordSet = $objCommand.Execute ConsoleWrite("Users"&@CR&"---------"&@CR) While Not $objRecordSet.EOF $strName = $objRecordSet.Fields ("sAMAccountName").Value $strCN = $objRecordSet.Fields ("cn").value $strdisplayName = $objRecordSet.Fields ("displayName").value $strSN = $objRecordSet.Fields ("SN").value $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value ;FileWriteLine("Users.txt",$strName) ConsoleWrite($strdisplayName&@cr) ConsoleWrite($strName&@cr) ConsoleWrite(@cr) $objRecordSet.MoveNext WEnd $objConnection.Close $objConnection = "" $objCommand = "" $objRecordSet = "" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now