Search code examples
c#uwpwindows-10desktop-bridgedesktop-app-converter

Running an app converted with the Windows Desktop Bridge as admin always?


I have an app that I've converted using the Desktop to UWP Bridge, specifically the Desktop App Converter which does it all automatically. It converts and installs fine but when I try to run it I recieve an error that the executable requires elevation. I can resolve this with Right Click -> Run as Administrator but I'd like the repackage the app with this as a default so this extra step isn't required. It's noteworthy that I can run the app as a normal install without admin privileges, it is only the converted app that requires this.

Is there a way to include the required elevation request in the AppxManifest.xml file associated with converting the app? I was hoping there would be something as simple as

<Application Id="MyApp" Permissions="Administrator">

There are docs on the manifest here but I can't find anything related to permissions or elevation levels.

This is the AppxManifest.xml generated by the converter.

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10">
  <Identity Name="MyApp" ProcessorArchitecture="x86" Publisher="CN=Me" Version="5.70.0.0" />
  <Properties>
    <DisplayName>MyApp</DisplayName>
    <PublisherDisplayName>Me</PublisherDisplayName>
    <Logo>Assets\AppStoreLogo.png</Logo>
  </Properties>
  <Resources>
    <Resource Language="en-us" />
    <Resource uap:Scale="100" />
    <Resource uap:Scale="125" />
    <Resource uap:Scale="150" />
    <Resource uap:Scale="200" />
    <Resource uap:Scale="400" />
  </Resources>
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
  </Dependencies>
  <Capabilities>
    <rescap:Capability Name="runFullTrust" />
  </Capabilities>
  <Applications>
    <Application Id="MyApp" Executable="Integrator.exe" EntryPoint="Windows.FullTrustApplication">
      <uap:VisualElements DisplayName="MyApp" Description="MyApp" BackgroundColor="transparent" Square150x150Logo="Assets\AppMedTile.png" Square44x44Logo="Assets\AppList.png">
        <uap:DefaultTile Wide310x150Logo="Assets\AppWideTile.png" Square310x310Logo="Assets\AppLargeTile.png" Square71x71Logo="Assets\AppSmallTile.png">
          <uap:ShowNameOnTiles>
            <uap:ShowOn Tile="square150x150Logo" />
            <uap:ShowOn Tile="wide310x150Logo" />
            <uap:ShowOn Tile="square310x310Logo" />
          </uap:ShowNameOnTiles>
        </uap:DefaultTile>
      </uap:VisualElements>
      <Extensions>
        <uap3:Extension Category="windows.fileTypeAssociation">
          <uap3:FileTypeAssociation Name="gfe">
            <uap:SupportedFileTypes>
              <uap:FileType>.gfe</uap:FileType>
            </uap:SupportedFileTypes>
          </uap3:FileTypeAssociation>
        </uap3:Extension>
        <uap3:Extension Category="windows.fileTypeAssociation">
          <uap3:FileTypeAssociation Name="gfs">
            <uap:SupportedFileTypes>
              <uap:FileType>.gfs</uap:FileType>
            </uap:SupportedFileTypes>
          </uap3:FileTypeAssociation>
        </uap3:Extension>
        <uap3:Extension Category="windows.appExecutionAlias" Executable="Integrator.exe" EntryPoint="Windows.FullTrustApplication">
          <uap3:AppExecutionAlias>
            <desktop:ExecutionAlias Alias="Integrator5.exe" />
          </uap3:AppExecutionAlias>
        </uap3:Extension>
      </Extensions>
    </Application>
  </Applications>
</Package>

Solution

  • Update: As of Windows 10 update 1809 (build 17763), you are now able to declare the 'allowElevation' capability to enable auto/self-elevation. Here is a tutorial on this capability: https://stefanwick.com/2018/10/01/app-elevation-samples-part-1/

    Previous answer (applies to pre-1809 builds of Windows 10):
    Auto-elevation for apps is not supported today. The user can choose to run your app as admin though.

    This policy is called out in the preparation guide for the Desktop Bridge: https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-prepare (bullet #2)

    Thanks, Stefan Wick - Windows Developer Platform