- May
- 13,594
- 201
I wanted to monitor the starting and stopping of a service. SERVICEMONITOR would be a lot easier to use if it ...
1. could watch for more than one condition (notably, STARTED or STOPPED), and
2. would only execute its <command> when the status changed (to a watched-for status). There doesn't seem to be much point in its executing the command several times a second.
I wrote service_monitor.btm (using @WMI) which gives me what I want.
To do that using SERVICEMONITOR I would have to write a BTM with a polling loop that alternated between
1. could watch for more than one condition (notably, STARTED or STOPPED), and
2. would only execute its <command> when the status changed (to a watched-for status). There doesn't seem to be much point in its executing the command several times a second.
Code:
v:\> servicemonitor WaaSMedicSvc stopped 5 `echo %_time %_servicename %_servicestate`
v:\> 11:37:16 WaaSMedicSvc 1
11:37:16 WaaSMedicSvc 1
11:37:16 WaaSMedicSvc 1
11:37:16 WaaSMedicSvc 1
11:37:16 WaaSMedicSvc 1
I wrote service_monitor.btm (using @WMI) which gives me what I want.
Code:
WaaSMedicSvc Started: 21:48:20 Stopped: 21:49:20
WaaSMedicSvc Started: 21:54:23 Stopped: 21:55:24
WaaSMedicSvc Started: 21:58:23 Stopped: 21:59:24
WaaSMedicSvc Started: 22:23:56 Stopped: 22:24:57
WaaSMedicSvc Started: 22:28:17 Stopped: 22:29:18
WaaSMedicSvc Started: 22:34:21 Stopped: 22:35:22
WaaSMedicSvc Started: 22:38:21 Stopped: 22:39:22
WaaSMedicSvc Started: 23:38:22 Stopped: 23:39:22
To do that using SERVICEMONITOR I would have to write a BTM with a polling loop that alternated between
servicemonitor WaaSMedicSvc started 1
and servicemonitor WaaSMedicSvc stopped 1
and only reported when _servicestate changed. That would have been cumbersome.