Start/stop Windows Service A also Start/stop Windows service B

dependenciesservicewindows-server-2003

I created two Windows services A and B, and would like to add dependency between them
so that I can:

  1. Start service A (service B starts automatically)

  2. Stop service A (service B stops automatically)

However, the command sc config ServiceA depend= ServiceB only works for:

  1. Start service A (service B starts automatically)

  2. Stop service B (service A stops automatically)

Is there any way to make service B stop automatically when I stop service A?

Best Answer

A dependency indeed only would work in a way that stopping service B would stop service A. If this is not what you want, dependencies are not for you and you would need something outside of the built-in service control mechanism doing this work. Using WMI to subscribe to an event triggered by the service stop command and some scripting to do the checks and stop the other service should do the trick.

Related Topic