AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WMI COM
Goto page 1, 2, 3  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Wed Feb 14, 2007 1:43 am    Post subject: WMI COM Reply with quote

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
View user's profile Send private message
Veovis



Joined: 13 Feb 2006
Posts: 389
Location: Utah

PostPosted: Wed Feb 14, 2007 1:56 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Helpy
Guest





PostPosted: Wed Feb 14, 2007 9:24 am    Post subject: Reply with quote

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

PostPosted: Wed Feb 14, 2007 9:48 am    Post subject: Reply with quote

works here
_________________
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Thu Feb 15, 2007 1:46 am    Post subject: Reply with quote

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
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1381
Location: USA

PostPosted: Thu Jul 31, 2008 12:13 am    Post subject: Reply with quote

broken link
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Thu Jul 31, 2008 4:40 am    Post subject: Reply with quote

ahklerner wrote:
broken link
The file is missing... I guess I deleted it. Anyway, I posted the script in top post.
Back to top
View user's profile Send private message
ladiko



Joined: 13 Jul 2006
Posts: 290
Location: Berlin

PostPosted: Mon Dec 29, 2008 9:45 am    Post subject: Reply with quote

thank you sean, i could solve my propblem with your com library and wmi query -> http://www.autohotkey.com/forum/topic39033.html
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sun Mar 01, 2009 6:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
ladiko



Joined: 13 Jul 2006
Posts: 290
Location: Berlin

PostPosted: Sun Mar 01, 2009 6:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sun Mar 01, 2009 6:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
ladiko



Joined: 13 Jul 2006
Posts: 290
Location: Berlin

PostPosted: Sun Mar 01, 2009 6:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sun Mar 01, 2009 8:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
ladiko



Joined: 13 Jul 2006
Posts: 290
Location: Berlin

PostPosted: Sun Mar 01, 2009 8:04 pm    Post subject: Reply with quote

--> http://www.autohotkey.com/forum/viewtopic.php?p=253141

Last edited by ladiko on Sun Mar 01, 2009 8:18 pm; edited 1 time in total
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sun Mar 01, 2009 8:08 pm    Post subject: Reply with quote

sure, but what I just described is better for the user
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group