Page 1 of 1

Common WMI tasks

Posted: 05 Feb 2014, 23:47
by tank
tank wrote:In light of my error in judgement and search skills. I am going to Reference
. jNizM's more a refined results and more useful as-is


Compiled from wmi-tasks-com-with-ahk-l
Posted here for ease. All credit to SBC and Shajul

WMI Tasks COM with AHK_L

Some examples from MSDN http://msdn.microsof...5(v=VS.85).aspx.

New users can convert all the MSDN examples given to Native AHK code, I am just giving some examples


CD-ROM drives details:

Code: [Select all] [Download] (script.ahk)GeSHi © Codebox Plus

strComputer := "." 
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")

colItems := objWMIService.ExecQuery("Select * from Win32_CDROMDrive")._NewEnum
While colItems[objItem]
MsgBox % "Device ID: " . objItem.DeviceID
. "`nDescription: " . objItem.Description
. "`nName: " . objItem.Name


Ping without ping.exe :

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



Computer system details:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



Operating system details and free physical memory:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



Properties of the mouse used on computer:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



List Desktop settings:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



List BIOS details

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus


Memory:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus


Onboard Devices:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus


Hard Drives:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus


Motherboard:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus


CPU:

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus


Product:

Code: [Select all] [Download] (script.ahk)GeSHi © Codebox Plus

;http://msdn.microsoft.com/en-us/library/aa394105%28v=vs.85%29.aspx 
PropertyList := "Caption,Description,IdentifyingNumber,Name,SKUNumber,UUID,Vendor,Version"
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . A_ComputerName . "\root\cimv2")
WQLQuery = Select * From Win32_ComputerSystemProduct
colSysProduct := objWMIService.ExecQuery(WQLQuery)._NewEnum
While colSysProduct[objSysProduct]
Loop, Parse, PropertyList, `,
ProductInfo .= A_LoopField . ":`t" . objSysProduct[A_LoopField] . "`n"
MsgBox % ProductInfo

****



List of Installed Applications

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



List of Installed Audio and Video Codecs

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



List of Fonts installed with Applications

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



List of User Accounts

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



List of System Accounts

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



List of Shared Folders and Printes

Code: [Select all] [Expand] [Download] (script.ahk)GeSHi © Codebox Plus



List of running processes (narrowed down to those which path can be retrieved)

Code: [Select all] [Download] (script.ahk)GeSHi © Codebox Plus

strComputer := "." 
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
colItems := objWMIService.ExecQuery("SELECT Caption,ExecutablePath,ProcessID FROM Win32_Process where ExecutablePath is not null")._NewEnum
While colItems[objItem]
MsgBox % "Caption: " . objItem.Caption
. "`nProcessID: " . objItem.ProcessID
. "`nExecutablePath: " . objItem.ExecutablePath

Re: Common WMI tasks

Posted: 06 Feb 2014, 00:35
by lexikos
There are color tags in many of the examples, which do not work.

Instead of using ._NewEnum and While, you can use a for-loop. For example, see below.

The string passed to ComObjGet can be shortened quite a bit in many cases. The local computer name \\.\ can be omitted. {impersonationLevel=impersonate}! and root\cimv2 can be omitted, provided that the default impersonation level and default namespace in the registry have their standard values.

For me, this makes it much easier to write WMI scripts from memory, without having to refer to documentation or other code.

Code: [Select all] [Download] GeSHi © Codebox Plus

; Get a list of executables running on this computer.
for obj in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where ExecutablePath is not null")
s .= obj.ExecutablePath "`n"
Sort s, U ; Remove duplicates.
MsgBox % s

I just learned that you can also get a specific WMI class or instance directly, though I'm not sure of the details. For example, this shows the file system of drive C:

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % ComObjGet("winmgmts:root\cimv2:Win32_LogicalDisk=""C:""").FileSystem

Get Process properties via AHK using WMI

Posted: 06 Feb 2014, 01:31
by hoppfrosch
Get Process properties:

Re: Common WMI tasks

Posted: 06 Feb 2014, 01:50
by jNizM

Re: Common WMI tasks

Posted: 08 Feb 2014, 09:03
by Menixator
jNizM wrote:AHK - WMI - Snippets
... -.-


LOL :P

Re: Common WMI tasks

Posted: 09 Feb 2014, 14:43
by tank
In light of my error in judgement and search skills. I am going to Reference
jNizM wrote:AHK - WMI - Snippets
... -.-
at the top of this. I was in the process of trying to remove duplicates from this thread and merge the topic to his when i realized for the most part that the entire thread was more refined versions of these calls. Most of the ones I compiled to this list are raw examples where His is more a refined results and more useful as-is

Re: Common WMI tasks

Posted: 14 Aug 2014, 10:49
by arcticir
I ask, can detect whether there is a touch screen, and get its message?


Like this, but I did not find the direct detection of the touch screen

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus


Re: Common WMI tasks

Posted: 13 Oct 2016, 01:42
by Tomer
very useful! tnx