I have a Windows Service which is working fine in most of the servers. But in one server, I see that it starts before the network services are started. This is causing the services to hang and as a result OS is not booting up. It also gets stuck. What is the usual start order of services? My Windows Service does make TCP connections. Should I add a delayed start? If that's the case, shouldn't all services be having a delayed start following these network services? Any help would be much appreciated.
Windows – the start order of services in Windows server
bootscmwindowswindows-server-2012-r2windows-service
Related Topic
- Windows service fails to start up after certain number of instances
- Windows – How to grant start/stop/restart permissions on a service to an arbitrary user or group on a non-domain-member server
- Windows Services don’t automatically start after reboot
- Stunnel as Windows service doesn’t “start” on reboot
- Windows Service with dependency cannot start automatically
Best Answer
Using Delayed Start may be one possible solution.
Another possibility is adding a dependency so that the services start up in the order that you want. For instance, you wouldn't want your service starting before, say, the NSI service, because network connectivity can't happen until the NSI service is running. So add a dependency.
From MSDN:
(More detail about the start order is in that MSDN article as well.)
Either of those two things might work, though, if I were you, I'd be more interested in figuring out what is different about this one server. It's a good idea to always fully understand what's happening and why before you go modifying system settings and making this one server a "special snowflake" compared to the others.
Edit:
You got me thinking more about the question, "what is the start order of services in Windows," I mean, the exact order, and I don't think the question has ever been thoroughly answered, at least not publically.
I think that's partly due to the fact that it's very complicated. The exact startup order of Windows services is always changing. There are "early start services," "phase 1 services," "phase 2 services," service groups, services that get started because they're dependencies, etc. etc. It'll be slightly different on every version and edition of Windows, and will also vary on different configurations and deployment options. So don't count on it ever being officially documented in anything other than the most generic, relative terms, such as "delay start services start after the auto-start services."
I think it's also partly because it's a bit of a non-deterministic situation. The Service Control Manager (services.exe in user mode) sends the start signal to a service, and the order of that part is pretty deterministic, but the time at which the start signal is sent and the time at which the service actually starts are two different things. Because of the preemptive nature of Windows, we can't always guarantee that service A will start before service B, even if the SCM sent service A the start control first. (Unless we use some sort of synchronization mechanism.)
Anyway, I figured I could at least enable some SCM logging during boot and see the SCM starting all the services, chronologically.
This is Windows 10, RS1/1607. As I mentioned before, your results would vary slightly on basically any other build. Results have been edited for length and content. First, I think it'll be most interesting to show the chronological order in which the services entered the Running state, not necessarily the order in which the SCM attempted to start them.
And next, we have a chronological listing of Windows services that the SCM sent start controls to. Notice this list is shorter. And it may not always be in the same order.