Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling start up sequence of a windows service

I have a windows service installed using installutil and set to "Autostart". My problem is that when some servers are rebooted it attempts to start before "Microsoft SQL service" has started- I can see this by looking at the event log during a system restart. What is the best way of making my service "auto start" AFTER Sql server service has started?

I am toying with the idea of creating a SQL job set to start when "SQL server agent" starts that in turn starts the windows service. But hopefully, there is an easy, effective way of controlling the order in which automatic services start up.

like image 280
Bijimon Avatar asked Jan 14 '09 02:01

Bijimon


3 Answers

Each Windows Service has a list of other services it depends on. That means it'll wait until its dependencies have started before it will attempt to start, and it'll start them for you if they weren't started automatically when yours is started.

If you're creating your Windows Service in .NET, there's a blog post here that might be helpful:

How to: Code Service Dependencies

Otherwise there's a Microsoft kb entry here that details a way to add service dependencies via the registry:

How to delay loading of specific services

like image 96
Matt Hamilton Avatar answered Oct 06 '22 22:10

Matt Hamilton


You can set dependencies between the services.

See here:

like image 24
Otávio Décio Avatar answered Oct 06 '22 21:10

Otávio Décio


If you want to do this with a batch script then the following will help

REG ADD "HKLM\SYSTEM\CurrentControlSet\Services\%ServiceKey%" /v "DependOnService" /t REG_MULTI_SZ /d "Service Number 01\0Service Number 02"

This uses reg.exe see here

like image 39
sadgit Avatar answered Oct 06 '22 21:10

sadgit