I develop an application in C# (.NET 4.6.2) that gets installed as a Windows service by an installer build via WiX 3. The service starts automatically when Windows starts.
On application startup the list of available network interfaces gets loaded via NetworkInterface.GetAllNetworkInterfaces()
.
Sometimes, on a computer running Windows 11, the returned list is empty and I cannot figure out the reason.
My guess (or better hope): There exists a built-in Windows service that does some kind of network interfaces initialization. And that service startup did not complete before the system started my service. Or my service start is scheduled before the network service start. Both situations would then explain why the returned list of interfaces is empty.
So my question is: Does such network service exist and what is the name of the service?
If so, I may be able to register a service dependency directly via WiX functionality and do not need to run, e.g., a custom action that does a call to sc triggerinfo start/networkon
. But, said that, I am even not sure if sc triggerinfo
may solve the issue.
I ended up setting the start type of my service to manual and adding a start trigger via p/invoke in a custom action.
The trigger does the same as sc triggerinfo start/networkon
. My service gets started, if network interfaces are ready while booting up the system.
MS DOCS: https://learn.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-changeserviceconfig2w