Jump to content

AD 'ExecQuery' error


TXTechie
 Share

Recommended Posts

Hello Everyone,

I've ported over the following script from VBScript (where it works fine) to AutoIt:

Dim $objDNS = ObjCreate("winMgmts:\\" & $strDNSServer & "\root\MicrosoftDNS")
Dim $objRR = $objDNS.ExecQuery("SELECT * FROM MicrosoftDNS_ResourceRecord" & _
" WHERE ContainerName='" & $strDomainName & "' AND OwnerName='" & $strOwnerName & "'",,48)

I have to compile the script and run it on a PC where the logged on user has the appropriate AD privileges. When I attempt to compile it (with AU3Check turned on) I get the following error:

ERROR: syntax error

" WHERE ContainerName='" & $strDomainName & "' AND OwnerName='" & $strOwnerName & "'",,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

If I turn off AU3Check and go ahead and compile the code, on the PC (where I know permissions is NOT the issue because I can run the same VBScript-syntaxed code on the same PC successfully) I get the following runtime error:

AutoIT Error

Line 436 [there are only 84 lines of code] (File "C:\Test.exe"):

Error: Variable must be of type "Object".

Can someone please hep me?
Link to comment
Share on other sites

You have 2 commas in a row with nothing in between them.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hi BrewManNH,

Yes, just like the original VBScript code that works:

Set objDNS = GetObject("winMgmts:\\" & strDNSServer & "\root\MicrosoftDNS")
Set objRR = objDNS.ExecQuery("SELECT * FROM MicrosoftDNS_ResourceRecord" & _
" WHERE ContainerName='" & strDomainName & "' AND OwnerName='" & strOwnerName & "'",,48)

I even tried it without the [,,48] and while it compiled without error, I received the same "variable must be of type Object" error.

Link to comment
Share on other sites

Try using ObjGet instead of ObjCreate.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Try this...

Local $objDNS = ObjGet('winmgmts:' & $strDNSServer & 'rootMicrosoftDNS')
Local $objRR = objDNS.ExecQuery('SELECT * FROM MicrosoftDNS_ResourceRecord WHERE ContainerName="' & _
        $strDomainName & '" AND OwnerName="' & $strOwnerName & '"', 'WQL', 0x30)

; Or my favorite way...

Local $objRR = objDNS.InstancesOf('MicrosoftDNS_ResourceRecord WHERE ContainerName="' & _
        $strDomainName & '" AND OwnerName="' & $strOwnerName & '"')
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Am I right that the thread has nothing do do with AD (Active Directory) as the threads title implies?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Try using ObjGet instead of ObjCreate.

Thank you, BrewManNH! Using ObjGet did the trick. In researching this in the forum (and in previous scripts where I've used objects), using ObjCreate seemed to be the primary way to use objects. I guess I still need to learn more about objects.

Can you (or someone) give me a good rule of thumb for when to use ObjGet and when to use ObjCreate?

Link to comment
Share on other sites

Am I right that the thread has nothing do do with AD (Active Directory) as the threads title implies?

Hi water,

Whlie this thread does not utilize the AD UDF, I specifically put AD in the subject line to differentiate between the Active Directory DNS service (which my script is manipulating) vs. local PC DNS settings (which I primarily saw when I searched through the forum).

Link to comment
Share on other sites

According to the help file:

ObjGet: Retrieves a reference to a COM object from an existing process or filename.

ObjCreate: Creates a reference to a COM object from the given classname.

With ObjGet you refer to an existing COM object, with ObjCreate you create one. In my Word, Excel and Outlook UDFs I first use ObjGet to check if a COM object already exists (means the suer already started Excel, Word or Outlook). If I get an error I use ObjCreate to create the object.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'm not sure ObjCreate works for all types of application. IIRC WMI is a service, so if ObjGet fails I'm sure ObjCreate fails too. WMI needs to be started differently.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Can someone assist me with how to better trap/handle the error I'm getting from the compiled script (Line 436) so that I can better determine where it is and what's going on?

I'm receiving the Error: Variable must be of type "Object". from the compiled script when the DNS Record that it is expecting is actually not in AD (it has been deleted). I'm assuming it's during this code that the error is thrown, since the AD "object" (the DNS Record) doesn't exist:

Dim $objRR = $objDNS.ExecQuery("SELECT * FROM MicrosoftDNS_ResourceRecord" & _
" WHERE ContainerName='" & $strDomainName & "' AND OwnerName='" & $strOwnerName & "'")

For $objRR2 In $objRR
...

Can anyone assist me?

Link to comment
Share on other sites

After the ExecQuery check that $objRR is of type object.

If IsObj($objRR) Then ... process the returned collection

Or you need a COM error handler. Please check function ObjEvent in the help file for an example.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I included the following error handling:

If $objRR = 0 Or Not IsObj($objRR) Then
; Display a MessageBox dialog with a yellow Exclamation-point icon and the "OK" button
MsgBox(48, $Title & " v" & $Version, "The [" & $strOwnerShortName & "] DNS Record was NOT found! Exiting the application.")

; Exit the script with error status = 1
Exit (1)
EndIf

But, I'm still getting the generic Error: Variable must be of type "Object". error. I'll look into the ObjEvent event in Help.

Thanks!

Link to comment
Share on other sites

Which line of your script raises the error?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Do you have any "#include" statements in your script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Why are you compiling it before you get it working?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

As I eluded to previously, I'm running the script on another PC that doesn't have AutoIt installed but the user has the appropriate AD privileges. So, I compile in order to run it there. I'm just wondering how everyone else deals with troubleshooting a compiled AutoIt script when it raises an error that you haven't already trapped/handled?

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...