create dependency between windows services startup create dependency between windows services startup windows windows

create dependency between windows services startup


You're looking for the ServiceInstaller.ServicesDependedOn Property for your project's ServiceInstaller component.

From the article's Remarks section (and I bolded the part you're interested in):

A service can require other services to be running before it can start. The information from this property is written to a key in the registry. When the user (or the system, in the case of automatic startup) tries to run the service, the Service Control Manager (SCM) verifies that each of the services in the array has already been started.

If any service in the array is not running then, the SCM tries to start them. This includes services with Manual StartType.

If any service upon which this service depends fails to start, this service will not start. An exception is not thrown if the system is not started because there is no exception handling at the system level to detect this. Decide how to handle service start failures and implement this in your code. Typically, a dialog appears to the user at startup if a service fails to start.

If the service does not start, an entry is written to the Application event log.

The services upon which this service depends do not need to be in the same executable.


In addition to Jay Riggs' answer, here's and example of what you should add to the serviceinstaller to make your service dependent on the eventlog

Me.ServiceInstaller1.ServiceName = "Service1";Me.ServiceInstaller1.ServicesDependedOn = new string[] {"EventLog"};

Off course, if you have another service dependency, change the 'Eventlog' to something else..


I use the advapi32.dll as I have full control over the installation. My services register themselves, set descriptions (though I use sc.exe), set dependencies, set restart on failures (also using sc.exe) etc.

ChangeServiceConfig2 API is supposed to set descriptions, but doesn't seem to work in .NET

The dependency is set by the CreateService API..

[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]internal static extern UIntPtr CreateService(UIntPtr SC_HANDLE, string lpSvcName, string lpDisplayName,        uint dwDesiredAccess, uint dwServiceType, uint dwStartType, uint dwErrorControl, string lpPathName,        string lpLoadOrderGroup, string lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword);