Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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