Output CPU and memory use for each process

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Output CPU and memory use for each process

Post by Marcus Tettmar » Tue Mar 21, 2006 3:17 pm

This script writes processor time and memory use for each running process on the system into a CSV file.

VBSTART
Sub DumpProcInfo(OutFile)
'Writes ProcessorTime and VirtualBytes (memory use) for each running process to file
'See: http://msdn.microsoft.com/library/defau ... rocess.asp

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process",,48)

Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile(OutFile, True)
filetxt.WriteLine("ProcessName,PercentProcessorTime,VirtualBytes")

For Each objItem in colProcess
if objItem.Name "Idle" and objItem.Name "_Total" then
filetxt.WriteLine(objItem.Name & "," & objItem.PercentProcessorTime & "," & objItem.VirtualBytes)
end if
Next

filetxt.Close
End Sub
VBEND

VBRun>DumpProcInfo,c:\procusage.txt
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts