c# - 始终以管理员身份运行使用 Windows 桌面桥转换的应用程序?

标签 c# uwp windows-10 desktop-bridge desktop-app-converter

我有一个使用 Desktop to UWP Bridge 转换的应用程序,特别是 Desktop App Converter这一切都是自动完成的。它可以很好地转换和安装,但是当我尝试运行它时,我收到一个错误,指出可执行文件需要提升。我可以通过 Right Click -> Run as Administrator 来解决这个问题,但我希望将应用程序重新打包为默认设置,这样就不需要这个额外的步骤了。值得注意的是,我可以在没有管理员权限的情况下以正常安装方式运行该应用程序,只有转换后的应用程序才需要这样做。

有没有办法在与转换应用相关联的 AppxManifest.xml 文件中包含所需的提升请求?我希望有像

这样简单的东西
<Application Id="MyApp" Permissions="Administrator">

list 上有文档 here但我找不到任何与权限或提升级别相关的信息。

这是转换器生成的AppxManifest.xml

<?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>

最佳答案

更新:从 Windows 10 更新 1809(内部版本 17763)开始,您现在可以声明“allowElevation”功能以启用自动/自行提升。这是有关此功能的教程:https://stefanwick.com/2018/10/01/app-elevation-samples-part-1/

上一个答案(适用于 1809 之前版本的 Windows 10):
目前不支持应用程序的自动提升。不过,用户可以选择以管理员身份运行您的应用。

Desktop Bridge 的准备指南中提到了此策略: https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-prepare (项目符号 #2)

谢谢, Stefan Wick - Windows 开发者平台

关于c# - 始终以管理员身份运行使用 Windows 桌面桥转换的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43267968/

相关文章:

docker - Windows10上的Docker卷权限 “a STORAGE ENGINE failed.”

c# - 在 Entity Framework Code First 中为关联实体的数量添加一个属性

c# - 使用 LLBLGen 多次连接到同一个表

c# - Web 方法可以重载吗?

c# - 如果我每次都没有取消配对我的蓝牙 LE 设备,为什么我不能发送消息? (UWP)

windows-10 - Windows 10 TTS 语音未显示?

c# - 如何在 VS2010 中创建 STA(单线程单元)控件

c# - Windows 10 邮件样式 ListView

c# - UWP 手动绑定(bind)处于非事件状态/变灰

go - 如何让 filepath.IsAbs 正确识别绝对路径?