Is there a way to monitor a particular process by it's name and get the amount of cpu usage that is occurring in percentage?
Thanks
Frank
Monitor A Process
Moderators: Dorian (MJT support), JRL
Re: Monitor A Process
Found a VBScript HERE. Had to modify it a bit to work in Macro Scheduler then had to divide the result by 2 to get the same result I see in Task Manager. Can't vouch for its accuracy but on my old WinXP laptop it is giving precisely the same CPU percentage as is being displayed in Task Manager at the moment I run the script. As posted the script is looking at FireFox.
Note: Adding .exe to the process name causes the script to report "0" so leave off the .exe from the process name.
Note: Adding .exe to the process name causes the script to report "0" so leave off the .exe from the process name.
Code: Select all
VBSTART
Function CPUUSage(ProcName)
On Error Resume Next
Set objService = GetObject("Winmgmts:{impersonationlevel=impersonate}!\Root\Cimv2")
For Each objInstance1 in objService.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process where Name = '" & ProcName & "'")
N1 = objInstance1.PercentProcessorTime
D1 = objInstance1.TimeStamp_Sys100NS
Exit For
Next
WScript.Sleep(1000)
For Each perf_instance2 in objService.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process where Name = '" & ProcName & "'")
N2 = perf_instance2.PercentProcessorTime
D2 = perf_instance2.TimeStamp_Sys100NS
Exit For
Next
Nd = (N2 - N1)
Dd = (D2 - D1)
PercentProcessorTime = ((Nd/Dd)/2) * 100
CPUUSage = Round(PercentProcessorTime ,0)
End Function
VBEND
vbeval>CPUUSage("Firefox"),res
MDL>res
Re: Monitor A Process
JRL, you rock!
Thank you so much.
Frank
Thank you so much.
Frank