WMI (Windows Management Instrumentation) – Win32

Introduction to WMI Win32

Although there are other classes of WMI objects, Win32 is the richest source of operating system component.  WMI uses Win32 components such as Process, Memory and DiskDrive to measure and control the operating system.  To be clear what I am talking about, WMI contacts the root\cimv2 namespace.  CIM (Common Information Model) is a database with numerous objects and properties.  What we are going to do is display the values of these CIM objects thanks to VBScript.

Topics for WMI – Win32

Our VBScript Shell to Interrogate Win32

I can see why most people use the famous ‘Hello world’ output to test their scripts, however, I prefer scripts that perform a real task, so in for this simple script I chose  to check the BIOS rather than say ‘Hello world’.

Prerequisites for your WMI Script

No specific requirements.  Surely, your computer has a BIOS that you can test?  Any systems from Windows 2000 onwards should have the necessary WSH, VBScript and WMI programs.

Instructions for Creating your Shell Script

  1. Copy and paste the example script below into notepad or a VBScript editor.
  2. Begin with strComputer = "."  Once the script works substitute the name of another machine on the network.
  3. Save the file with a .vbs extension, for example: BIOS.vbs 
  4. Double click BIOS.vbs and check the information in the message box.

Example Shell VBScript / WMI Script

‘ Shell.vbs
‘ Sample VBScript to display very basic BIOS information
‘ Author Guy Thomas https://computerperformance.co.uk/
‘ Version 1.5 – December 2010
‘ ———————————————–‘
Option Explicit
Dim objWMIService, objItem, colItems, strComputer

‘ On Error Resume Next
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" _
& strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery(_
"Select * from Win32_BIOS")

For Each objItem in colItems
Wscript.Echo "Computer " & strComputer & vbCr & _
"Caption: " & objItem.Caption & VbCr & _
"Description: " & objItem.Description & VbCr & _
"Name: " & objItem.Name & VbCr & _
"Additional Properties (Up to your research!)" & VbCr & _
""
Next
WSCript.Quit

‘ End of Sample WMI / VBScript

WMI Tutorial Learning Points

1) Do make sure that the first item after ‘For Each objItem in colItems’, has a WScript.Echo statement.  Also be aware that the last statement does not require & VbCr, precisely because it is the last line, there is no need for any more word-wrap.

2) As this script is designed to be a shell, or template, you can add additional Properties after this line:
"Additional Properties" & VbCr & _

Guy Recommends: WMI Monitor and It’s Free!Solarwinds Free WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory or Exchange Server. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

Win32 Objects and Properties

Mix and match.  Copy and paste different object and their particular properties of interest.

Key line to change: "Select * from Win32_BIOS")

 Win32_Object

Properties to Add to the Shell

 Win32_BIOS "BuildNumber: " & objItem.BuildNumber & vbCr & _
"Manufacturer: " & objItem.Manufacturer & VbCr & _
"PrimaryBIOS: " & objItem.PrimaryBIOS & vbCr & _
"SMBIOSBIOSVersion: " & objItem.SMBIOSBIOSVersion & vbCr & _
"SMBIOSMajorVersion: " & objItem.SMBIOSMajorVersion & vbCr & _
"SMBIOSMinorVersion: " & objItem.SMBIOSMinorVersion & vbCr & _
"SMBIOSPresent: " & objItem.SMBIOSPresent & vbCr & _
"SoftwareElementID: " & objItem.SoftwareElementID & vbCr & _
"TargetOperatingSystem: " & objItem.TargetOperatingSystem & vbCr & _
"OtherTargetOS: " & objItem.OtherTargetOS & vbCr & _
Win32_BootConfiguration "BootDirectory: " & objItem.BootDirectory & VbCr & _
"ConfigurationPath: " & objItem.ConfigurationPath & VbCr & _
"LastDrive: " & objItem.LastDrive & VbCr & _
Win32_Bus "BusNum: " & objItem.BusNum & vbCr & _
"BusType: " & objItem.BusType & vbCr & _
"CreationClassName: " & objItem.CreationClassName & vbCr & _
"DeviceID: " & objItem.DeviceID & vbCr & _
"PNPDeviceID: " & objItem.PNPDeviceID & vbCr & _
"SystemName: " & objItem.SystemName & vbCr & _
Win32_Desktop "CoolSwitch: (Windows + d) " & objItem.CoolSwitch & vbCr & _
"CursorBlinkRate: " & objItem.CursorBlinkRate & vbCr & _
"DragFullWindows: " & objItem.DragFullWindows & vbCr & _
"GridGranularity: " & objItem.GridGranularity & vbCr & _
"IconSpacing: " & objItem.IconSpacing & vbCr & _
"IconTitleFaceName: " & objItem.IconTitleFaceName & vbCr & _
"IconTitleSize: " & objItem.IconTitleSize & vbCr & _
"IconTitleWrap: " & objItem.IconTitleWrap & vbCr & _
"Pattern: " & objItem.Pattern & vbCr & _
"ScreenSaverActive: " & objItem.ScreenSaverActive & vbCr & _
"ScreenSaverExecutable: " & objItem.ScreenSaverExecutable & vbCr & _
"ScreenSaverSecure: " & objItem.ScreenSaverSecure & vbCr & _
"ScreenSaverTimeout: " & objItem.ScreenSaverTimeout & vbCr & _
"SettingID: " & objItem.SettingID & vbCr & _
"Wallpaper: " & objItem.Wallpaper & vbCr & _
Win32_ComputerSystems "AdminPasswordStatus: " & objItem.AdminPasswordStatus & vbCr & _
"AutomaticResetBootOption: " & objItem.AutomaticResetBootOption & vbCr & _
"AutomaticResetCapability: " & objItem.AutomaticResetCapability & vbCr & _
"BootROMSupported: " & objItem.BootROMSupported & vbCr & _
"BootupState: " & objItem.BootupState & vbCr & _
"Caption: " & objItem.Caption & vbCr & _
"ChassisBootupState: " & objItem.ChassisBootupState & vbCr & _
"CreationClassName: " & objItem.CreationClassName & vbCr & _
"CurrentTimeZone: " & objItem.CurrentTimeZone & vbCr & _
"DaylightInEffect: " & objItem.DaylightInEffect & vbCr & _
"Description: " & objItem.Description & vbCr & _
"DNSHostName: " & objItem.DNSHostName & vbCr & _
"Domain: " & objItem.Domain & vbCr & _
"DomainRole: " & objItem.DomainRole & vbCr & _
"FrontPanelResetStatus: " & objItem.FrontPanelResetStatus & vbCr & _
"InfraredSupported: " & objItem.InfraredSupported & vbCr & _
"InitialLoadInfo: " & objItem.InitialLoadInfo & vbCr & _
"InstallDate: " & objItem.InstallDate & vbCr & _
"KeyboardPasswordStatus: " & objItem.KeyboardPasswordStatus & vbCr & _
"LastLoadInfo: " & objItem.LastLoadInfo & vbCr & _
"Manufacturer: " & objItem.Manufacturer & vbCr & _
"Model: " & objItem.Model & vbCr & _
"NetworkServerModeEnabled: " & objItem.NetworkServerModeEnabled & vbCr & _
"NumberOfProcessors: " & objItem.NumberOfProcessors & vbCr & _
"PartOfDomain: " & objItem.PartOfDomain & vbCr & _
"PauseAfterReset: " & objItem.PauseAfterReset & vbCr & _
"PowerManagementCapabilities: " & objItem.PowerManagementCapabilities & vbCr & _
"PowerManagementSupported: " & objItem.PowerManagementSupported & vbCr & _
"PowerOnPasswordStatus: " & objItem.PowerOnPasswordStatus & vbCr & _
"PowerState: " & objItem.PowerState & vbCr & _
"PowerSupplyState: " & objItem.PowerSupplyState & vbCr & _
"TotalPhysicalMemory: " & objItem.TotalPhysicalMemory & vbCr & _
"UserName: " & objItem.UserName & vbCr & _

Summary of Basics of WMI

WMI (Windows Management Instrumentation) provides all the commands that you need to investigate Microsoft’s operating systems objects, their properties and their values.  What makes WMI difficult at the beginning is the many skills that you need, in particular VBScript and WQL, which is like SQL.  All will be explained if you follow my examples on the following pages.

 

If you like this page then please share it with your friends

 


See more VBScript WMI examples:

WMI Tutorial   • WMI Who Logged On   • WMI WBEMTest   • Free WMI Monitor   • Free WMI Monitor

WMI Secrets   • VBScript Services   • WMI Techniques   • WMI Scriptomatic

WMI Home   • WMI Moniker   • Import CSVDE – Free Utility   • VBScript Echo   • WMI VBScript