| View previous topic :: View next topic |
| Author |
Message |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Wed Feb 14, 2007 1:43 am Post subject: WMI COM |
|
|
It's a WMI script. I take Win32_Process as an example this time, as there was an interest in GetCommandLine recently, which can be obtained via WMI too.
| Code: | COM_Init()
;WMI_Query("\\.\root\cimv2", "Win32_Process")
WMI_Query("\\.\root\cimv2", "Win32_Process WHERE Name='svchost.exe'")
MsgBox % "<CommandLine>`n" . WMI_Query("\\.\root\cimv2", "Win32_Process WHERE Name='autohotkey.exe'", "CommandLine")
COM_Term()
Return
WMI_Query(Namespace, Class, Property = "")
{
psvc := COM_GetObject("winmgmts:{impersonationLevel=impersonate}!" . Namespace)
pset := COM_Invoke(psvc, "ExecQuery", "SELECT * FROM " . Class)
penm := COM_Invoke(pset, "_NewEnum")
Loop, % COM_Invoke(pset, "Count")
If COM_Enumerate(penm,pobj)=0
{
If Not Property
MsgBox % COM_Invoke(pobj, "GetObjectText_")
Else sResult.=COM_Invoke(pobj, Property) . "`n"
COM_Release(pobj)
}
COM_Release(penm)
COM_Release(pset)
COM_Release(psvc)
Return sResult
}
|
Last edited by Sean on Thu Jul 31, 2008 4:38 am; edited 4 times in total |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 389 Location: Utah
|
Posted: Wed Feb 14, 2007 1:56 am Post subject: |
|
|
using latest ahk version on XP SP2 i got an empty message box over and over. i am very excited about getting this to work though. _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
Helpy Guest
|
Posted: Wed Feb 14, 2007 9:24 am Post subject: |
|
|
| Works for me, thanks. It fills a frequently asked field (often for hardware information requests, like HID). |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Wed Feb 14, 2007 9:48 am Post subject: |
|
|
works here _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Thu Feb 15, 2007 1:46 am Post subject: |
|
|
| Veovis wrote: | | using latest ahk version on XP SP2 i got an empty message box over and over. i am very excited about getting this to work though. |
Is it Pro or Home edition?
If you're on Pro, would you try wmic.exe or wbemtest.exe? They reside under system32\wbem folder which is actually on Path. Do they work?
Or if you're on Home, you may try to see if work MS's apps like scriptomatic or wmicodecreator, both can be downloaded from MS site. |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Thu Jul 31, 2008 12:13 am Post subject: |
|
|
broken link _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Thu Jul 31, 2008 4:40 am Post subject: |
|
|
| ahklerner wrote: | | broken link | The file is missing... I guess I deleted it. Anyway, I posted the script in top post. |
|
| Back to top |
|
 |
ladiko
Joined: 13 Jul 2006 Posts: 290 Location: Berlin
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun Mar 01, 2009 6:11 pm Post subject: |
|
|
Cool! Great work!
With “Win32_USBControllerDevice” I can have a list of the installed USB devices. I have to filter out the joysticks, but how can I know, which one is connected now, and what is its OEM name? Could you direct me to some documentation or example code? |
|
| Back to top |
|
 |
ladiko
Joined: 13 Jul 2006 Posts: 290 Location: Berlin
|
Posted: Sun Mar 01, 2009 6:37 pm Post subject: |
|
|
search for the device pid/vid in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ ... ?
could you post the sample code that outputs the list of usb devices?! |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun Mar 01, 2009 6:44 pm Post subject: |
|
|
I got the usb-list code from Guest++.
Stupid question: If I can get the data from the registry, why should I use the COM interface? Is it faster, more reliable, more flexible...? |
|
| Back to top |
|
 |
ladiko
Joined: 13 Jul 2006 Posts: 290 Location: Berlin
|
Posted: Sun Mar 01, 2009 6:53 pm Post subject: |
|
|
is it a joystick/joypad that is listed in the device manager as usb hid device? than you should find it in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID
if it is something else: what are you searching for? |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun Mar 01, 2009 8:00 pm Post subject: |
|
|
| ladiko wrote: | | what are you searching for? | I need a list of all joystick names currently plugged in, with their number, so the user can select which one to use. I could steal the list from the control panel app Game Controllers, but it does not tell their number AHK uses (because already removed joysticks still occupy numbers). In the thread I linked above I described a solution via reading the registry and calling winmm\joyGetPos with each one, but it has some problems: winmm\joyGetPos leaks memory, the registry sometimes very slowly gets updated. I hoped for a faster and more robust solution, like reading the information joyGetPos returns, but no one seems to know how to use it (the last field of the returned struct). |
|
| Back to top |
|
 |
ladiko
Joined: 13 Jul 2006 Posts: 290 Location: Berlin
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun Mar 01, 2009 8:08 pm Post subject: |
|
|
| sure, but what I just described is better for the user |
|
| Back to top |
|
 |
|