Purpose:Monitor service start, pause, and / or stop

 

Format:SERVICEMONITOR [/C [name]]

SERVICEMONITOR name STARTED | PAUSED | STOPPED n command

 

nameDevice name
nNumber of repetitions (or FOREVER)
commandCommand to execute when condition is triggered

 

/C(lear)

 

Usage:

 

The service name can include wildcards.

 

The command line will be parsed and expanded before SERVICEMONITOR is executed, so if you want to pass redirection characters or variables to command you will need to protect them (by enclosing in single back quotes, doubling the %'s, or using command grouping).

 

If the last argument on the line is a single (, it is interpreted as the beginning of a command group. SERVICEMONITOR will append the following lines (in a batch file) or prompt you for more input (at the command line) until it gets a closing ).

 

If you don't enter any arguments, SERVICEMONITOR will display the services it is currently monitoring.

 

The monitoring runs asynchronously in a separate thread. When the condition is triggered, the command will be executed immediately. This may cause problems if you try to write to the display or access files while the main TCC-RT thread is also performing I/O. You may need to use START or DETACH in command to avoid conflicts.

 

SERVICEMONITOR creates several environment variables when a service is started, paused, or stopped that can be queried by command. The variables are deleted after command is executed.

 

_servicedisplayDisplay name used by service control programs to identify the service

 

_servicenameThe name of the service in the service control manager database

 

_servicecountThe number of times the command has been triggered

 

_servicestateThe current state of the service. The possible values are:

 

1The service is stopped
2The service is starting
3The service is stopping
4The service is running
5The service continue is pending
6The service pause is pending
7The service is paused

 

Example:

 

Send an email if the service "mytestservice" stops:

 

SERVICEMONITOR mytestservice STOPPED sendmail [email protected] "Service Stopped" The Windows service "mytestservice" stopped!

 

Options:

 

/CIf name is specified, remove the monitor for that service. Otherwise, remove all service monitors.