Calling the AppServiceConnection's openAsync() method fails if the app is started with administrator privileges

L-proger 6 Reputation points

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
connectionStatus = _appServiceConnection->OpenAsync().get();

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:

  1. Clone sample UWP service application ("server"):
  2. Clone sample service client application ("client"):
  3. Build and deploy UwpService application
  4. In VisualStudio in project UwpService open "Package.appxmanifest" file in designer. Go to tab "Packaging", copy value of "Package family name" field.
  5. Open UwpServiceClient project, open file "UwpServiceClient.cpp", go to line 14, replace PackageFamilyName with your own, copied in step 4
  6. 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?

Universal Windows Platform (UWP)
{count} vote