Jump to content

Problem with ADODB Command


BluAlien
 Share

Recommended Posts

Hello all !

I'm new about his forum and AutoIt3 scripting language. So I have a problem with ADODB. Comand code, with VBS it works perfectly, but with AutoIt I got an error.

VBS CODE

____________________

Set objConnection = CreateObject("ADODB.Connection")

objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")

objCommand.ActiveConnection = objConnection

objCommand.CommandText = "<GC://ou=" & strOU & "," & strDCDomain & ">;(objectCategory=User)" & _

";userAccountControl,distinguishedName,sAMAccountName;subtree"

Set objRecordSet = objCommand.Execute

AUTOIT CODE

____________________

$objConnection = ObjCreate("ADODB.Connection")

$objConnection.Open ("Provider=ADSDSOObject;")

$objCommand = ObjCreate("ADODB.Command")

$objCommand.ActiveConnection = $objConnection

$objCommand.CommandText = "<GC://OU=" & $strOU & "," & $strDCDomain & ">;(objectCategory=User);userAccountControl,distinguishedName,sAMAccountName;subtree"

$objCommand.ActiveConnection = $objConnection

$objRecordset = $objCommand.Execute()

$objRecordset = $objCommand.Execute()

Link to comment
Share on other sites

Sorry .. some problem with tab key, so sent the incomplete post. Down here he complete post. Thanks

Hello all !

I'm new about his forum and AutoIt3 scripting language. So I have a problem with ADODB. Comand code, with VBS it works perfectly, but with AutoIt I got an error.

VBS CODE

____________________

Set objConnection = CreateObject("ADODB.Connection")

objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")

objCommand.ActiveConnection = objConnection

objCommand.CommandText = "<GC://ou=" & strOU & "," & strDCDomain & ">;(objectCategory=User)" & _

";userAccountControl,distinguishedName,sAMAccountName;subtree"

Set objRecordSet = objCommand.Execute

AUTOIT CODE

____________________

$objConnection = ObjCreate("ADODB.Connection")

$objConnection.Open ("Provider=ADSDSOObject;")

$objCommand = ObjCreate("ADODB.Command")

$objCommand.ActiveConnection = $objConnection

$objCommand.CommandText = "<GC://OU=" & $strOU & "," & $strDCDomain & ">;(objectCategory=User);userAccountControl,distinguishedName,sAMAccountName;subtree"

$objCommand.ActiveConnection = $objConnection

$objRecordset = $objCommand.Execute()

Running the AutoIT code i got the 80020009 - Table does not exist.

Any Ideas ?

Thanks a lot in advance !

Link to comment
Share on other sites

$objCommand.ActiveConnection = $objConnection

That line is repeated a 2nd time in the AutoIt conversion compared to a single line used in the VBS. Not sure if it is your problem but worth looking into.

:)

Link to comment
Share on other sites

That line is repeated a 2nd time in the AutoIt conversion compared to a single line used in the VBS. Not sure if it is your problem but worth looking into.

:)

Thanks, but it's a my writing error (during the firs post I pressed accidentally one or more keys so the sytem duplicated some row and submitted the post). Right down here there is the code:

just to be more detailed I saw that the error comes out executing the "execute" method in the last line. So, the objects Connection and Command are created without any problem, but executing the query I gotthe error. It seems as if the query string ("<GC://OU=...") wasn't passed in right way; perhaps AutoIT interpreter adds someting to the string, so the Provider mistakes to find the object (in this case the error reports that cannot find the Table). The same string with BVS works perfectly.

$objConnection = ObjCreate("ADODB.Connection")

$objConnection.Open ("Provider=ADSDSOObject;")

$objCommand = ObjCreate("ADODB.Command")

$objCommand.ActiveConnection = $objConnection

$objCommand.CommandText = "<GC://OU=" & $strOU & "," & $strDCDomain & ">;(objectCategory=User);userAccountControl,distinguishedName,sAMAccountName;subtree"

$objRecordset = $objCommand.Execute()

bye

Link to comment
Share on other sites

OK, we will look into the help file for ObjEvent() to help us with error handling. You may see the syntax supports use of error handling and the example below shows it's usage. The code below is the addition of the ObjEvent() error handler and may show you a better description of the error that you are receiving.

; Initialize a COM error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$objConnection = ObjCreate("ADODB.Connection")
$objConnection.Open ("Provider=ADSDSOObject;")
$objCommand = ObjCreate("ADODB.Command")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText = "<GC://OU=" & $strOU & "," & $strDCDomain & ">;(objectCategory=User);userAccountControl,distinguishedName,sAMAccountName;subtree"
$objRecordset = $objCommand.Execute() 


; This is my custom defined error handler
Func MyErrFunc()

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
            
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    
    SetError($err)  ; to check for after this function returns
Endfunc

:)

Link to comment
Share on other sites

OK, we will look into the help file for ObjEvent() to help us with error handling. You may see the syntax supports use of error handling and the example below shows it's usage. The code below is the addition of the ObjEvent() error handler and may show you a better description of the error that you are receiving.

; Initialize a COM error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$objConnection = ObjCreate("ADODB.Connection")
$objConnection.Open ("Provider=ADSDSOObject;")
$objCommand = ObjCreate("ADODB.Command")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText = "<GC://OU=" & $strOU & "," & $strDCDomain & ">;(objectCategory=User);userAccountControl,distinguishedName,sAMAccountName;subtree"
$objRecordset = $objCommand.Execute() 


; This is my custom defined error handler
Func MyErrFunc()

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
            
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    
    SetError($err)  ; to check for after this function returns
Endfunc

:)

The error I got with the Autoit script and that I reported on previous post was already taken with the "MyErrFunct" using $oMyError.description and hex($oMyError.number,8) properties.
Link to comment
Share on other sites

Try this:

Local   $crit       =   "sAmAccountname"    ; filter of query. here, an account name
Local   $value      =   "joe"               ; the account
Local   $domn       =   "test"              ; your domain name
Local   $query, $objConnection, $objCommand, $objRecordSet, $disting, $obusr

    $query          =   "<LDAP://"& $domn &">;(&(ObjectCategory=User)(" & $crit & "=" & $value & "));DistinguishedName;subtree"
    
    $objConnection  =   ObjCreate("ADODB.Connection")
    $objCommand     =   ObjCreate("ADODB.Command")
    $objConnection.open ("Provider=ADsDSOObject")
    
    $objCommand.ActiveConnection    = $objConnection
    $objCommand.CommandText         = $query
    
    $objRecordSet   = $objCommand.Execute

    $disting        = $objRecordSet.Fields("DistinguishedName").value

    $objconnection.close        ;Fermer la requete AD
    
    $obusr = ObjGet("LDAP://"& $disting)

; You can now request all information you want
MsgBox(64,"User query test","given name=" &$obusr.givenName)

Exit

Regards

Joe

registry victim

Link to comment
Share on other sites

Try this:

Local   $crit    =     "sAmAccountname"    ; filter of query. here, an account name
Local   $value  =    "joe"        ; the account
Local   $domn    = "test"            ; your domain name
Local   $query, $objConnection, $objCommand, $objRecordSet, $disting, $obusr

    $query    =    "<LDAP://"& $domn &">;(&(ObjectCategory=User)(" & $crit & "=" & $value & "));DistinguishedName;subtree"
    
    $objConnection  =     ObjCreate("ADODB.Connection")
    $objCommand  =   ObjCreate("ADODB.Command")
    $objConnection.open ("Provider=ADsDSOObject")
    
    $objCommand.ActiveConnection    = $objConnection
    $objCommand.CommandText         = $query
    
    $objRecordSet   = $objCommand.Execute

    $disting        = $objRecordSet.Fields("DistinguishedName").value

    $objconnection.close       ;Fermer la requete AD
    
    $obusr = ObjGet("LDAP://"& $disting)

; You can now request all information you want
MsgBox(64,"User query test","given name=" &$obusr.givenName)

Exit

Regards

Joe

Joell, thanks for your help but unfortunately it doesn't work. The error is exactly the same: Error 80020009 - Table does not exist.

bye

Posted Image

post-24067-1181724124_thumb.jpg

Link to comment
Share on other sites

Now this is the (more complete) code with the MyErrFunction in it, as MHz suggested me, and attached there is the full error message I got with this code.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$strOU = "Test_OU"

$strDCDomain = "dc=Mydom,dc=com"

$objConnection = ObjCreate("ADODB.Connection")

$objConnection.Open ("Provider=ADsDSOObject")

$objCommand = ObjCreate("ADODB.Command")

$objCommand.ActiveConnection = $objConnection

$objCommand.CommandText = "<GC://ou=" & $strOU & "," & $strDCDomain & ">;(objectCategory=user);userAccountControl,distinguishedName,sAMAccountName;subtree"

$objCommand.ActiveConnection = $objConnection

$objRecordset = $objCommand.Execute()

Func MyErrFunc()

Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _

"err.description is: " & @TAB & $oMyError.description & @CRLF & _

"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _

"err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _

"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _

"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _

"err.source is: " & @TAB & $oMyError.source & @CRLF & _

"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _

"err.helpcontext is: " & @TAB & $oMyError.helpcontext _

)

EndFunc

post-24067-1181743237_thumb.jpg

Link to comment
Share on other sites

Try this , change your

$objRecordset = $objCommand.Execute()oÝ÷ ÚX§zÚºÚ"µÍ    ÌÍÛØXÛÜÙ]H   ÌÍÛØÛÛ[X[^XÝ]J   ][ÝÉ][ÝË    ][ÝÉ][ÝËJ
Sorry, nothing to do... now the error is : 80020009 - No such interface suported.

Tanks

Link to comment
Share on other sites

Sorry, nothing to do... now the error is : 80020009 - No such interface suported.

Tanks

OK, scratch that. I just did some testing here at the office and I have narrowed the problem down to either your

$strOU = "Test_OU"

or

$strDCDomain = "dc=Mydom,dc=com"

variables.

So, make sure your "Test_OU" actually exists in your domain as an OU. To test here, I just substituted "Domain Controllers" as in

$strOU = "Domain Controllers"

and of course I changed the "dc=Mydom" to our domain, and voila your script as last posted ran without errors (with your original "$objRecordset = $objCommand.Execute()" command.)

If I change my $strOU to an OU that doesn't exist in our domain, then I get the "table doesn't exist" error. Likewise if I change my "dc=" to something other than our actual domain.

So, I suspect either your "Test_OU" OU doesn't exist, or you've made a typo on your 'dc=" line.

Link to comment
Share on other sites

OK, scratch that. I just did some testing here at the office and I have narrowed the problem down to either your or variables.

So, make sure your "Test_OU" actually exists in your domain as an OU. To test here, I just substituted "Domain Controllers" as in

$strOU = "Domain Controllers"

and of course I changed the "dc=Mydom" to our domain, and voila your script as last posted ran without errors (with your original "$objRecordset = $objCommand.Execute()" command.)

If I change my $strOU to an OU that doesn't exist in our domain, then I get the "table doesn't exist" error. Likewise if I change my "dc=" to something other than our actual domain.

So, I suspect either your "Test_OU" OU doesn't exist, or you've made a typo on your 'dc=" line.

I agree with you, in some way the "Table Does Not Exist" error means that query points to a non existent object, so it could be e typo in OU or domain variables. But, as you can see in the attachment, I pulled out with a message box both autoit and vbs object command text, that are identical (or seems to be). As I told in the first post, the VBS runs perfectly, but AutoIT got the error. Posted ImagePosted Image

I tried also with "Domain Controllers" OU, and the result is the same. VBS is OK, Autoit fails. The only thing that I omitted is that the Domain Controller is a LongHorn Beta 3 (on a VMvare Virtual Machine), but looking at AD structure with ADSI Edit, all path are correct. Today I'm going to try with a Windows 2003 R2... just to be shure ...perhaps something is changed in AD api.

Thanks !

post-24067-1181895632_thumb.jpg

Link to comment
Share on other sites

Hello you all, I solved the problem simply using Windows2003 Domain Controller insted of new Longhorn. The bad thing is that with VBS I didn't find any problem, so be aware in future for migration to the new S.O., autoit scripts could stop running (I hope none in final release).

Thanks a lot to ResNullis for the time spent giving me support.

bye

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...