Scheduling starting a service after another service

5

3

I have a service that needs to be started only AFTER another service. Is there some way to configure the service to only start once another has finished starting?

Obviously, I could use a delayed start or write a batch script to do this, but they are both messy / temporary solutions. So I wondered if I can schedule for this to happen somehow?

Can it be done?

Nobody

Posted 2010-09-14T13:54:09.477

Reputation: 153

What version of Windows? – JNK – 2010-09-14T14:02:45.363

Windows Server 2008 – Nobody – 2010-09-14T14:17:42.590

Answers

5

In my experience, the best way to create service dependencies, without rummaging in the registry (something that is not secure, safe, or easily scriptable == repeatable) is to use SC.exe - the service control utility packaged with every Windows version since Win2003.

You can open a command window and type sc to get the full help, but the gist of it is:

sc create newservice binpath= c:\nt\system32\newserv.exe type= own start= auto depend= "netbios"

Creates a new service, named "newservice", points to its path, makes it start automatically and makes it dependent on the NetBIOS service.

Read more about SC here.

Traveling Tech Guy

Posted 2010-09-14T13:54:09.477

Reputation: 8 743

5

You have to use the registry editor (as far as I know) to make the service depend on the other server. Locate the dependent service in HKLM\SYSTEM\CurrentControlSet\services, and add an REG_MULTI_SZ value called DependOnService. Put the service name (not the display name, but the same name as it's reg key) as a value.

When you reboot now, Windows will only start your dependent service after the service you made it depend on starts. Likewise, if the service it depends on fails to start, your dependent service will not start either.

Coding Gorilla

Posted 2010-09-14T13:54:09.477

Reputation: 706

1Brilliant. I am not sure how happy my buildmaster will be about poking around in the registry though... They definately need to add this functionality, I can't imagine this is a unique problem – Nobody – 2010-09-14T14:21:19.987

Here's the Microsoft Support article on this topic.

– Phrogz – 2011-05-04T16:30:17.647

2

As long as the service is deployed properly in webcontainer, when you start the tomcat, it would automatically starts the service just like any other web application. Please be aware that webservice deployed in webcontainer is nothing but a service wrapped in a servlet which looks for SOAP request over HTTP just like any other servlet.

user19391

Posted 2010-09-14T13:54:09.477

Reputation: 29

1

You could make the second service dependent on the first service, and then start the second service instead of the first service. Windows will make sure that the first service is started before starting the second service.

dsolimano

Posted 2010-09-14T13:54:09.477

Reputation: 2 778

the flip side of this is that you can't run service A without service B ALSO running...which may be OK for this purposes but he should be aware of it. – JNK – 2010-09-14T14:11:02.870

Thanks. I just found the dependencies tab for the service but there are no options to set or add dependencies - how can I do that? @JNK that's not an issue here but good point – Nobody – 2010-09-14T14:15:53.527

You can certainly have service A run without service B, unless we've gotten our A's and B's confused. E.g., the Fax service (service B, or the second service) depends on the Print Spooler service (service A, or the first service), but starting Print Spooler doesn't also start Fax. Starting Fax will start Print Spooler. – dsolimano – 2010-09-14T14:18:11.600

@sdolimano - I was backwards, sorry. It's a moot point according to OP anyways... – JNK – 2010-09-14T14:19:17.740

@rmx, you can look at http://support.microsoft.com/kb/193888 or Coding Gorilla's answer.

– dsolimano – 2010-09-14T14:19:26.413