Got a question from Brett this week:
“Hi Steve. I have a tough one for you. I want to determine from a VBScript if a program is using too much CPU time. Specifically, I want to know when the spooler service goes over 50% CPU utilization. All the scripts I see don’t seem to work like task manager (The CPU time reported by the script is much higher). Thanks, and keep it up.”
Thanks Brett. I did some testing, and indeed you are correct that all of the scripts I found report CPU usage differently than task manager.
The reason for this is that the scripts are reporting the percentage of usage on one specific core.
What you need to do is find out how many cores there are and then divide the cpu usage by that number.
After lots of experimenting with different versions of Windows, I came up with a script that will do this on Windows XP through 2008 R2.
Click here to download the script
(Rename to .VBS after downloading)
If you open the script, and scroll to the bottom…you can see how to use it.
In your case, we want to check the spooler process. On Windows 7 it is named “spoolsv”. I want to check once a minute, and if it goes over 50%, the script will show a message box.
Here is how I would do that:
'Check our spooler for over 50% cpu time
if (check_process_cpu_time("spoolsv",50)) then
MsgBox "Spooler is running high on CPU Time!"
'Wait a minute before checking again
I wouldn’t set the checking time for less than a minute, since the script itself takes some work to get this info.
Also, notice that the name you use for the process does not include the file extension. In our example we want to watch
spoolsv.exe, so we provide
spoolsv to the script.
Now Brett will know when his printer spooler is jacked up, before he starts getting phone calls.
One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools