Playing with WMI and VBscript

Today I was having a play with some Vbscript to retreive some permon counters. Windows provides a interface called WMI (Windows Management Instrumentation) which allows among other things to retreive performance data.

Here is some code to provide some task information for the iexplore.exe process.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Wscript.Echo "Name, PID, Kernel Time, PageFaults"
Set colItems = objWMIService.InstancesOf("Win32_Process")
For Each objItem In colItems
If objItem.Description = "iexplore.exe" Then
Wscript.Echo objItem.Description, objItem.ProcessId, objItem.KernelModeTime, objItem.PageFaults
End if
Next

You run it from the command line using cscript you can use wscript but all the text is piped with a windows message box.
cscript filename.vbs

Here is what it outputed on my machine.

Leave a comment