mr_unreliable
Mon Apr 10 18:01:42 CDT 2006
Josh, I don't know of a "pure script" way to address this,
but if you are courageous enough (or foolhardy enough) to
call api's from script, then there is a "standard way" of
testing if an application is responding.
The "usual" approach is to send the app a system message,
and see if it responds. The api used is "SendMessageTimeout",
which sends a message, and waits for a fixed period to see
if the message is handled. The "tricky part" may be picking
an appropriate timeout period.
Here are a couple of (vb) source code sites having suggested
code:
http://www.thescarms.com/VBasic/AppResponse.asp
http://www.visualbasic.happycodings.com/Applications-VBA/code29.html
The relevant api's to get the app's window handle and to
SendMessageTimeout are callable by DynaWrap, an actX object
used for calling api's from script.
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
--- <DynaWrap Boilerplate> ---
It is possible to declare-and-call an api from script,
but you must use a third-party control to do so,
or else write one yourself.
It has already been correctly pointed out that there
is no api-capability in "pure" script.
If you are willing to use a third-party control, then
one such control, called "DynaWrap", can be found on
Guenter Born's website (note: Guenter refers to it as
"DynaCall"). Here is the link to it:
http://people.freenet.de/gborn/WSHBazaar/WSHDynaCall.htm
On that page you will find a download for the control,
plus some code samples.
Note: you may find additional sample code by searching
the archives of the wsh and vbscript ng's.
Note also: DynaWrap does have its limitations. There are
certain things it can't do. For example, you can't call
api's which take typedefs as parameters, and you can't call
api's "by ordinal". But it will work for most of the
"usual suspects".
And finally, DynaWrap doesn't work entirely as advertised.
For example, it is supposed to allow for the declaration of
several api definitions in one instance of itself. I could
never get that to work (in win9x). You will need a new
instance of DynaWrap for every api, or else re-instantiate
the object for every api. Someday I'm going to learn enough
c++ to fix that...
--- </DynaWrap Boilerplate> ---
josh wrote:
> I have written a script that restarts services that have stopped, that
> are set to auto start. The problem I'm having is that hanging services
> don't get identified, and therefore remain in a hung state. Is there a
> way using VBscript to identify a hung service?
>
> Thanks, any help is greatly appreciated,
>
> Josh
>