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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s