Skip to content

Using AppService with runFullTrust Desktop bridge and allowElevation #93

@Ruud-cb

Description

@Ruud-cb

I have:

  • An UWP App
  • A Console App (.NET Framework)
  • A Package project

This is (part of) the package.appxmanifest that tells you how it is setup:

  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
  </Dependencies>

  <Resources>
    <Resource Language="x-generate"/>
  </Resources>

  <Applications>
    <Application Id="App"
      Executable="$targetnametoken$.exe"
      EntryPoint="$targetentrypoint$">
      <uap:VisualElements
        DisplayName="CularBytes W10 App"
        Description="Package"
          .... />
      </uap:VisualElements>
      <Extensions>
        <uap:Extension Category="windows.appService">
          <uap:AppService Name="SampleInteropService" />
        </uap:Extension>
        <desktop:Extension Category="windows.fullTrustProcess" Executable="CularBytes.App.WindowsApp.Bridge\CularBytes.App.WindowsApp.Bridge.exe"/>
      </Extensions>
    </Application>
  </Applications>

  <Capabilities>
    <Capability Name="internetClient" />
    <rescap:Capability Name="runFullTrust" />
    <rescap:Capability Name="allowElevation" />
  </Capabilities>

As you can see I want to run it in the same process.

The Console app contains an app.manifest, so that I can define elevated permissions needed:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Within the Console app I start the AppService connection:

        private static async void InitializeAppServiceConnection()
        {
            AppServiceConnection Connection = new AppServiceConnection();
            Connection.AppServiceName = "SampleInteropService";
            Connection.PackageFamilyName = Package.Current.Id.FamilyName;
            Connection.RequestReceived += Connection_RequestReceived;
            Connection.ServiceClosed += Connection_ServiceClosed;

            AppServiceConnectionStatus status = await Connection.OpenAsync();
            if (status != AppServiceConnectionStatus.Success)
            {
                // something went wrong ...
                Console.WriteLine("status not success on connecting, status:" + status + " pacakgeName:" + Connection.PackageFamilyName);

            }
            else
            {
                Console.WriteLine("Status success!");
            }
        }

Somewhere from the UWP app, I start the FullTrustProcess like documented:

        if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
        {
            await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
        }

The console app starts like expected but the connection is not successful, console.writeline prints:

status not success on connecting, status:Unknown pacakgeName:df84c6a8....

I verified that the packageName is correct.

When I remove <rescap:Capability Name="allowElevation" /> from Package.appxmanifest and <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> from app.manifest, then the connection is successful!

So why, due elevated client-app, is the connection not working?

I need elevated permissions to do more actions from the console app. Don't bother asking what that is, I know I will have Microsoft Store limitations, etc. Please help me solve this issue.

Do I need to use another packageName? Is that changed when using allowElevation? How can I find this out?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions