I wrote a UWP app (let's call it "server") with the UWP service inside it and a C++ desktop app (let's call it "client") that connects to the server's UWP service using the WinRT API.
The following code works as expected if the client application is run as a login user::
//Executed inside newly created thread winrt::init_apartment(); connectionStatus = _appServiceConnection->OpenAsync().get(); winrt::uninit_apartment();
But this code doesn't work if I run the "client" application "as an administrator". (connectionStatus == AppServiceConnectionStatus::Unknown and I see "access denied" exception deeply inside windows libraries).
I don't need to use the WinRT API with admin rights, but other parts of the "client" app sometimes need to do this. Thus, the user should be able to run the "client" with or without administrator rights.
I have a separate thread dedicated to connecting to the UWP service and processing connection. I tried to drop the elevated rights of the thread security token, but was unsuccessful.
Steps to reproduce:
Clone sample UWP service application ("server"): https://github.com/L-proger/UwpService.git
Clone sample service client application ("client"): https://github.com/L-proger/UwpServiceClient.git
Build and deploy UwpService application
In VisualStudio in project UwpService open "Package.appxmanifest" file in designer. Go to tab "Packaging", copy value of "Package family name" field.
Open UwpServiceClient project, open file "UwpServiceClient.cpp", go to line 14, replace PackageFamilyName with your own, copied in step 4
Build and run UwpServiceClient application.
Working case: In step 6 you will see "Connect success!" message in console output.
Not working case: Run VisualStudio with administrator privileges, repeat step 6, you will see "Connect fail!" message in console output. Or run compiled UwpServiceClient executable from Explorer by right-clicking it and selecting "Run as administrator". Or run powershell terminal as administrator and run UwpServiceClient executable using terminal.
Do you have any suggestions?