I'm quite new to AutoHotKey
and I'm having a problem with COM
objects.
What I'm trying to mimic is this Powershell
one-liner:
(Get-WMIObject Win32_PnPEntity).GetDeviceProperties("DEVPKEY_Device_BusReportedDeviceDesc").DeviceProperties.Data
The code I have, so far, is like this:
#NoEnv ; Don't check empty variables to see if they are environment variables.
#Warn ; Enable warnings.
#SingleInstance Force ; Force single instance.
SendMode, Input ; Send is an alias for SendInput. Faster and safer.
SetNumLockState, AlwaysOn ; NumLock is always on, the key does not have any future effect.
SetWorkingDir, % A_Desktop
DetectHiddenWindows, On ; Detect hidden windows, needed for PostMessage.
for device in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_PnPEntity") {
keys := ComObjArray(0xC, 1) ; VT_VARIANT
props := ComObjArray(0xC, 1)
keys[0] := "DEVPKEY_Device_BusReportedDeviceDesc"
result := device.GetDeviceProperties(keys, props)
if (!result)
MsgBox, % props[0]
}
The function call returns 0, which as far as I know is correct. But the props
array seems to be empty.
I think I now the problem: props
is a ByRef
variable, but I tried with some code I found to create ByRef
variables (here) in order to get return values, without any success.
Obviously I'm doing something wrong with the function call, because I'm absolutely clueless about how to use COM
from AutoHotKey
.
Yes, I know I could use setupapi.dll
here, or some third-party library, or even the PowerShell one-liner, but I'm trying to learn how to use COM from AutoHotKey
, how to call COM
objects methods, etc.
So, any help is much appreciated. Thanks a lot in advance.
Here is GetDeviceProperties function signature, for reference.