简体   繁体   中英

Windows 2016: ServiceController.DisplayName returns ServiceController.ServiceName on Windows Start

I have a service (Main), which is responsible for taking care of other Windows Services. It decides which services need to be stopped, started, etc.

The Main service controls other services by DisplayNames. On the Windows start it reads DisplayNames from config and threats other services.

On Windows 2016 it takes some time to start services, and ServiceControl.DisplayName returns ServiceController.ServiceName, so the Main service is not able to find a service from config.

Does some workaround exist to fix this?

I think, might you can try to wait for specific status?

For example :

ServiceController.WaitForStatus(ServiceControllerStatus.Running); is going to wait until its status is " Running ". It's suspended an application's processing until the service has reached the required status. Here is a documentation .

And also, you can check out this article - ServiceController in C# .

Let me know if it worked.

Display Names, as the name suggests, are intended to be displayed. They are not meant to be compared to anything, and that used to determine a match.

For program to program interaction, you should be using the service names.

So your question is based on a bad premise - that display names are stable and may be relied upon. However distasteful it may seem, you need to re-architect your system to not rely on display names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM