Trax

Documentation on $oWMIService.ExecQuery

10 posts in this topic

#1 ·  Posted

That function seems to be used a lot to query the WMI. Where can I find documentation on that function with all the various parameters?

Share this post


Link to post
Share on other sites



#2 ·  Posted

That function seems to be used a lot to query the WMI. Where can I find documentation on that function with all the various parameters?

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hi @Trax

ExecQuery is not a function, it's a method linked to the object it is used with, in your case a WMIService object.

This means you can't use ExecQuery with every objects. You can only use it with objects that include this method.

When an object include this method, you can find the parameters of ExecQuery in microsoft libraries, like this one:

https://msdn.microsoft.com/en-us/library/aa393866(v=vs.85).aspx

But it doesn't mean that all ExecQuery method will use the same parameters, as it can change relating the object it is associated to. 

If you want to know the exact parameters, you need to refer to the library of the object you want to interact with :)

Share this post


Link to post
Share on other sites

#4 ·  Posted

I suggest to check the Example Scripts forum for Scriptomatic. That's a GUI which lets you create WMI scripts in AutoIt.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

   Thanks guys. My problem wasn't the WMI Query it was displaying the results. A bonehead move on my part. The code works. I have a For=>Next loop I don't need. Even if the WMI Query returns several items I am only interested in the first one. I just can't figure out the syntax to get rid of the For/Next loop:

Func FindScanner()
    Local $NumericPort, $TestDevice, $KeyName, $PortName
    Local $oWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
    $CommPort = ""
    If @error Then
        Return SetError(@error, 0, "")
    EndIf
    Local $ColItems = $oWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE 'My Unique Serial Port%'", "WQL", 48)
    If Not IsObj($ColItems) Then
        Return
    EndIf
    For $ColItem In $ColItems
        $KeyName = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $colItem.DeviceID & "\Device Parameters"
        $PortName = RegRead($KeyName, "PortName")
        If @error Then
            ContinueLoop
        EndIf
        $NumericPort = Int(StringReplace($PortName, "COM", ""))
        $CommPort = $PortName
        If ($NumericPort > 9) Then
            $CommPort = "\\.\" & $CommPort
        EndIf
        ExitLoop
    Next
    EndFunc

 

Edited by Trax

Share this post


Link to post
Share on other sites

#6 ·  Posted

Your script is looking for hardware in your computer with names containing "COM".

As COM (serial) ports are usually old and not included with recent computers, if your computer does not contains one, the query will obviously not return anything.

Are you sure that your computer has a COM (serial) port? It looks like this:

_SRPRUSB.JPG

And how do you want to match a com (serial) port to an audio hardware?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

See anything wrong with this statement? Typo?

$Result = FindScanner()
If $Results = -1 Then
    Exit
EndIf


Here's an example which has been tested:

 

 

Local $_objError = ObjEvent('AutoIt.Error', '_objErrorHandler')
;
Local $sReturn = Example()
MsgBox(0, 'Results', $sReturn)
Exit
;
Func Example()
    Local $objWMI = ObjGet('winmgmts:\\localhost\root\CIMV2')
    Local $objItems = $objWMI.ExecQuery('SELECT * FROM Win32_PnPEntity WHERE Name LIKE "%COM%"')
    If @error Then
        Return 'Object Error'
    ElseIf $objItems.count = 0 Then
        Return 'No Objects Found'
    Else
        Return 'Objects Found: ' & $objItems.count
    EndIf
EndFunc
;
Func _objErrorHandler($_objError)
    $_objError.Clear
    Return SetError(1)
EndFunc
;

 

 

 

Edited by ripdad
typo

Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

#8 ·  Posted

User's manual here  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted

Shoot. I crossed posts. Please look back at my last post. Thanks!

Share this post


Link to post
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