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?


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.

| improve this answer | |

If A is dependent on B then all that means is that A needs B to be running therefore - If you start A then it will automatically start B first - If you stop B then A will be stopped first

If you stop A there is no reason for B to stop - if you have access to the source code of service A you could get it to stop B programatically when itself is stopped.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.