Observe Windows Service Dependencies

I recently wrote a Windows service and installed it on a production system. After some applied Windows updates, the server had to restart, and my service did not load correctly, although it was configured to start automatically. The service began to work manually after we noticed a customer failure. After some research, I found out that I skipped to add a service dependency to our service. Therefore, the order of loading services was incorrect for our case.

I could fix this problem, but now I'm really interested in a tool or procedure on how to collect all the necessary service dependencies. Do you know any part of the code that can handle this?

I appreciate any hint.

+4
source share
2 answers

How does the tool know which services you need? By analyzing the source code? Starting the service until the service completes with an error?

The only way to make this work is to find out the services you depend on and add them to the registry when you install the service.

I am not saying that automation is impossible. but if it can be automated, then Windows will already do this: when connected to another service, Windows can stop starting until another service appears.

+3
source

Services and their dependencies are described in the Registry in HKLM / System / CurrentControlSet / Services / xxx, where xxx is the name of the service. There are hundreds of services, and only a few are visible in the Services.msc console. In the services console, you can open the properties window for the service and see the Dependencies tab. It will list the services that depend on the service, as well as the services on which the service depends. In the registry, each service has two optional keys named "DependOnService" and "DependOnGroup". Both are of type REG_MULTI_SZ, which means that they can contain multiple values. Use RegEdt32.exe when viewing these values. Dependencies are defined here. If you want your service to depend on Microsoft SQL Server, for example, in your service key, add a key called "DependOnService" containing "MSSQLSERVER". Check this by looking at the Dependencies tab of your service properties.

If you want to find service dependencies, you need to programmatically go through the Services key in the registry, specifying the services and services on which they depend. Once you have done this, you can simply print the results.

I wrote something similar to this when I wanted to find dependencies between .NET assemblies.

+2
source

All Articles