AutoHotkey Community

It is currently May 26th, 2012, 5:14 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 40 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: WMI COM
PostPosted: February 14th, 2007, 2:43 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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 July 31st, 2008, 5:38 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2007, 2:56 am 
Offline

Joined: February 13th, 2006, 10:40 pm
Posts: 389
Location: Utah
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.

_________________
Image
"Power can be given overnight, but responsibility must be taught. Long years go into its making."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2007, 10:24 am 
Works for me, thanks. It fills a frequently asked field (often for hardware information requests, like HID).


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2007, 10:48 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
works here

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2007, 2:46 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2008, 1:13 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
broken link

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2008, 5:40 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
ahklerner wrote:
broken link
The file is missing... I guess I deleted it. Anyway, I posted the script in top post.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2008, 10:45 am 
Offline

Joined: July 14th, 2006, 12:31 am
Posts: 290
Location: Berlin
thank you sean, i could solve my propblem with your com library and wmi query -> http://www.autohotkey.com/forum/topic39033.html


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 7:11 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 7:37 pm 
Offline

Joined: July 14th, 2006, 12:31 am
Posts: 290
Location: Berlin
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?!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 7:44 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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...?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 7:53 pm 
Offline

Joined: July 14th, 2006, 12:31 am
Posts: 290
Location: Berlin
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 9:00 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 9:04 pm 
Offline

Joined: July 14th, 2006, 12:31 am
Posts: 290
Location: Berlin
--> http://www.autohotkey.com/forum/viewtopic.php?p=253141


Last edited by ladiko on March 1st, 2009, 9:18 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 9:08 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
sure, but what I just described is better for the user


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 40 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group