Windows 10 pro, all latests updates are installed.
I have some C# code using P/Invoke calls to wlanapi functions such as creating profiles and connecting to the network.
The same behavior is observed using APIs directly or running "netsh wlan connect". It works from terminal/desktop app, but it doesn't work when invoked from within a service.
If I compile this as a desktop application it all works fine, but if I try to run the same code from a windows service, the call to WlanConnect() fails with "ERROR_INVALID_PARAMETER" (with identical arguments as from a desktop counterpart).
WlanSetProfile() works both from a service and a desktop application.
The service runs with the same user, and I've tried with <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> in the app manifest as well.
I have also tested to start a process from within the windows service running "netsh wlan connect name=<profile>" and the same problem persists.
Netsh works fine if I run it from the terminal, but if I start this process from within a service it fails with: "Connection request failed with error 0x57."
I have read the documentation https://docs.microsoft.com/en-us/windows/win32/api/wlanapi/ but I can't find any limitations invoking this API from a service.