|Purpose:||Monitor service start, pause, and / or stop|
|Format:||SERVICEMONITOR [/C [name]]|
SERVICEMONITOR [/=] name STARTED | PAUSED | STOPPED n command
|n||Number of repetitions (or FOREVER)|
|command||Command to execute when condition is triggered|
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 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.
|_servicedisplay||Display name used by service control programs to identify the service|
|_servicename||The name of the service in the service control manager database|
|_servicecount||The number of times the command has been triggered|
|_servicestate||The current state of the service. The possible values are:|
|1||The service is stopped|
|2||The service is starting|
|3||The service is stopping|
|4||The service is running|
|5||The service continue is pending|
|6||The service pause is pending|
|7||The service is paused|
Send an email if the service "mytestservice" stops:
SERVICEMONITOR mytestservice STOPPED sendmail email@example.com "Service Stopped" The Windows service "mytestservice" stopped!
|/=||Display the SERVICEMONITOR command dialog to help you set the command line options. The /= option can be anywhere on the line; additional options will set the appropriate fields in the command dialog.|