2

I have a Windows service A that depends on service B.

According to this Microsoft KB article I can add a registry key to tell Windows to wait until B starts before starting A.

Can I therefore expect service A to be shut down before B when I shut down Windows?

Ed Guiness
  • 267
  • 6
  • 13

2 Answers2

1

Unfortunately not prior to Windows Vista.

Here's the word from the horse's mouth: http://support.microsoft.com/kb/203878

Windows Vista (and newer versions) have a "Service Shutdown Ordering" feature. This is controlled by the "PreShutDownOrder" registry value (briefly mentioned in http://technet.microsoft.com/en-us/magazine/2007.03.vistakernel.aspx).

Searching "PreShutDownOrder" with "site:microsoft.com" on Google is returning an unhelpfully low number of results. It looks like it's only quasi-documented by Microsoft. I'd play around with it and see if it does what you want.

Here's a blog entry that mentions it from the "Ask Perf" blog (a really great blog, BTW, if you like knowing about Windows innards): https://techcommunity.microsoft.com/t5/Ask-The-Performance-Team/WS2008-Service-Shutdown-and-Crash-Handling/ba-p/372708

yurez
  • 103
  • 3
Evan Anderson
  • 141,071
  • 19
  • 191
  • 328
  • Is this still valid for 2003/2008 servers? – pauska Jul 01 '09 at 12:48
  • I've dropped another edit on this with some more info on a "PreShutDownOrder" feature that proports to be in Windows Vista and above, but seems to be very poorly documented. – Evan Anderson Jul 01 '09 at 12:53
  • http://serverfault.com/questions/24821/how-to-add-dependency-on-a-windows-service-after-the-service-is-installed – fjsj May 07 '15 at 22:09
0

A service who has other services depedent on it shuts down the other services before shutting it self when you do it manually.

Edit: Evan Anderson posted a link about it not using depdencies when shutting down the OS in case of running on UPS etc. It's a good and valid point (allthough it doesnt mention Windows newer than 2000.)

pauska
  • 19,532
  • 4
  • 55
  • 75
  • Service B might be unaware of Service A, so it cannot be expected to do anything. Windows, on the other hand, should but doesn't. – Ed Guiness Jul 01 '09 at 12:52
  • No, if you do the registry settings that you posted then service B will see service A as depedant on it. – pauska Jul 01 '09 at 12:54
  • Service B will only be aware of this registry key if it explicitly goes looking for it. Many services don't. It is not there for the benefit of services, it is there for the operating system, so it can work out which services to start first. – Ed Guiness Jul 01 '09 at 15:51
  • In my scenario, Service A is a service written by me, Service B is sql server. Sql server knows nothing about my service (nor should it) and therefore has no sensitivity to shutting down while my service is running. Do you see? – Ed Guiness Jul 01 '09 at 15:53
  • Doesnt that depend on how the service shuts down? Net stop and similar atleast takes attention to depedencies, but anyways: If you are talking about system shutdown then the poster above have the correct answwer. – pauska Jul 01 '09 at 19:10