Re: Checking CPU Usage for a Particular Process



hi ignignokt,

There may be some obscure performance counter that will give
you what you want, but I have another suggestion.

This will involve calling an api, and if that is distasteful
to you, then you will have to wait around for a better answer.

Still here? Then here's what you do... You "ping" your
(potentially stalled) application. How to "ping" an app?
You send it a message, and see if it responds. Generally,
"SendMessageTimeout" is used, and the suggested message is
"WM_NULL" (a harmless message). Here is a snippet of code,
which is used by the task manager to check if an app
"is awake":

--- <> ---
DWORD dwResult;
BOOL fResponding = SendMessageTimeout(hwndInQuestion,
WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);
// fResponding is TRUE if the thread is responding and
// FALSE if not.
--- <> ---

O.K. so it's c++ code, but it ought to be simple enough
to understand. If the app is "not responding" to the
message you send, then that's a good indication that
it is hung.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


ignignokt wrote:
I have a vbscript that will call a program and wait til the program is
finished to continue running the script. There are some cases where
the program will get hung and just freeze. I would like to have the
script check the CPU usage of the program after it is called, and if
the CPU usage is 0%, then it will kill the process and the script will
contiune running. Does anyone know how to do this in vbscript?

.