Installing a Windows Service with dependencies

后端 未结 5 937
小蘑菇
小蘑菇 2020-12-15 21:18

My installer program doesn\'t suppport installing services but I can run a program/command line etc so my question is how can I install a Windows Service and add 2 dependenc

5条回答
  •  离开以前
    2020-12-15 21:45

    This can also be done via an elevated command prompt using the sc command. The syntax is:

    sc config [service name] depend= 
    

    Note: There is a space after the equals sign, and there is not one before it.

    Warning: depend= parameter will overwrite existing dependencies list, not append. So for example, if ServiceA already depends on ServiceB and ServiceC, if you run depend= ServiceD, ServiceA will now depend only on ServiceD.

    Examples

    Dependency on one other service:

    sc config ServiceA depend= ServiceB
    

    Above means that ServiceA will not start until ServiceB has started. If you stop ServiceB, ServiceA will stop automatically.

    Dependency on multiple other services:

    sc config ServiceA depend= ServiceB/ServiceC/ServiceD
    

    Above means that ServiceA will not start until ServiceB, ServiceC, and ServiceD have all started. If you stop any of ServiceB, ServiceC, or ServiceD, ServiceA will stop automatically.

    To remove all dependencies:

    sc config ServiceA depend= /
    

    To list current dependencies:

    sc qc ServiceA
    

提交回复
热议问题