In this article, I will show how to set the dependencies on a Windows Service of a service or services through its registry or through Visual Studio.
In this article, I will show how to set the dependencies on a Windows Service of a service or services through its registry or through Visual Studio.Suppose after a reboot you need your service to be started automatically but many times we know certain services are required to be started before your service starts. In other words, your service is dependent on certain service(s) or we could say our service will not start until those services are started. Just for the sake of clarity, let us assume we have a Windows service or a WCF service (hosted on a Windows service) that checks its database connectivity on its startup. So before starting this service, the SQL Server Agent Service must be started. In this situation, Windows allows you to create service dependencies to take care of this. The Service dependency can be set either through the registry or through Visual Studio. 1. Service dependency setting through its RegistryLet us see how to set a service dependency through its registry. Even if you are not familiar with the registry at all, here is the step-by-step procedure to do this:
But what if you don't find any entry for the "DependOnService" entry then you need to create a new one for this by right-clicking the service name then select "New" -> "Multi-string value".Enter the name "DependOnService" then modify this new record and add the service name (for example Winmgmt) that you want to start before your service (for example MyDemoService). After successfully adding the dependent service name for your service, your service will be set as in the following image:How to get Actual Service Name not Display NameTo add a prerequisite service against the 'DependOnService' entry, you need to ensure you have the actual service name instead of the service's display name. To get the actual service name use the following procedure:
1. Service dependency setting through Visual StudioTo set service dependency through Visual Studio (2010), you need to open the 'ProjectInstaller' of the service and then open the properties of its 'Service Installer'. Add the dependent service name (in other words Winmgmt) by clicking the ellipses button. See the following images for more clarity:Summary:
So in this article we learned how we add a service dependency for any given service through its registry or through Visual Studio.
Pro WPF: Windows Presentation Foundation in .NET 3.0