Common WMI tasks

Post your working scripts, libraries and tools
User avatar
tank
Posts: 2160
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Louisville KY
Contact:

Common WMI tasks

05 Feb 2014, 23:47

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
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
lexikos
Posts: 5415
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Common WMI tasks

06 Feb 2014, 00:35

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
User avatar
hoppfrosch
Posts: 299
Joined: 07 Oct 2013, 04:05
GitHub: hoppfrosch
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Get Process properties via AHK using WMI

06 Feb 2014, 01:31

Get Process properties:
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Common WMI tasks

06 Feb 2014, 01:50

[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
Menixator
Posts: 68
Joined: 30 Sep 2013, 04:10

Re: Common WMI tasks

08 Feb 2014, 09:03

jNizM wrote:AHK - WMI - Snippets
... -.-


LOL :P
We live alone. We die alone. Everything else is just an illusion.
User avatar
tank
Posts: 2160
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Louisville KY
Contact:

Re: Common WMI tasks

09 Feb 2014, 14:43

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
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
arcticir
Posts: 471
Joined: 17 Nov 2013, 11:32

Re: Common WMI tasks

14 Aug 2014, 10:49

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

User avatar
Tomer
Posts: 202
Joined: 21 Aug 2016, 05:11

Re: Common WMI tasks

13 Oct 2016, 01:42

very useful! tnx

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 16 guests