Trax Posted August 11, 2017 Posted August 11, 2017 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?
Trax Posted August 11, 2017 Author Posted August 11, 2017 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?
Neutro Posted August 11, 2017 Posted August 11, 2017 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 Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water!
water Posted August 11, 2017 Posted August 11, 2017 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 2024-07-28 - Version 1.6.3.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 (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
Trax Posted August 11, 2017 Author Posted August 11, 2017 (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 August 11, 2017 by Trax
Neutro Posted August 11, 2017 Posted August 11, 2017 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: And how do you want to match a com (serial) port to an audio hardware? Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water!
ripdad Posted August 11, 2017 Posted August 11, 2017 (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 August 11, 2017 by ripdad typo "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Trax Posted August 11, 2017 Author Posted August 11, 2017 Shoot. I crossed posts. Please look back at my last post. Thanks!
Developers Jos Posted August 11, 2017 Developers Posted August 11, 2017 merged. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
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