I built a window service that depends on MSMQ service. Recently, the service failed to start automatically on reboot. While digging through error log, I found out that the service could not start since MSMQ service was not up and running.
Window service allows to add dependency so that service waits to start till the dependant service is up and running.
You can check the service dependencies from Dependencies tab of service properties.
Here are steps to add dependencies
- Click Start, click Run, type regedit.
- On Registry Editor window, Click to expand on HKEY_LOCAL_MACHINE, expand SYSTEM, expand CurrentControlSet, expand services
- Right click on the service name that you need to edit, Click New, Click Multi-String Value
- On the right hand side, you would see a new REG_MULTI_SZ type is added.
- Rename the key to DependOnService
- Right click on the DependOnService key, Click Modify.
- The Edit Multi-String Dialog box will appear.
- Type the service name, that the current service depends on, in the Value data textfield. (In my case, this would be MSMQ)
- Click Start, click Run, type services.msc
- Right click on your service name, click Properties.
- Click Dependencies Tab, you should see the service, current service depends, on as below
That’s it. Test it with a reboot. Make sure that your service startup type is Automatic.