How do you make your stop/start service scripts gracefully handling the services that get stuck in STOP_PENDING or START_PENDING…
Related with SC STOP and START. Stop and Start a service via batch or cmd file?
I have one aproach in mind, but I don’t like it.
This is the way i’m approaching the stop.
Loop with a maximum number of iterations (e.g. 30). Testing if service is stopped (e.g. sc %host% query %service% | find /i “STOPPED”). Wait some seconds in each iteration (e.g. 10). Reaching the maximum iterations, try to kill the process using taskkill (e.g. work the output of sc queryex Alerter | find /i “PID”).