在开始菜单快捷方式中添加可执行参数

Add executable parameter in start menu shortcut

我有一个用 gcc-g++ 编译的可执行文件,比方说 launcher.exe。我想 运行 它作为 launcher.exe --param。因此,我制作了一个包含所有资产、二进制文件等的 UWP 文件夹。我可以使用 makeappx.exe 成功地将文件夹打包到 APPX 包中,并使用 signtool.exe 进行播放。它安装并成功启动。但是我无法在 appxmanifest.xml 文件中添加 --param。清单文件如下:

 <Applications>
    <Application Executable="launcher.exe" EntryPoint="Windows.FullTrustApplication" Id="test">
      <uap:VisualElements DisplayName="launcher" Square44x44Logo="Assets\test44x44.png" Description="" BackgroundColor="transparent" Square150x150Logo="Assets\test150x150.png">
        <uap:InitialRotationPreference>
          <uap:Rotation Preference="portrait"/>
          <uap:Rotation Preference="landscape"/>
        </uap:InitialRotationPreference>
      </uap:VisualElements>
      <Extensions>
        <rescap3:Extension Category="windows.desktopAppMigration">
          <rescap3:DesktopAppMigration>
            <rescap3:DesktopApp ShortcutPath="%APPDATA%\Microsoft\Windows\Start Menu\Programs\test\launcher.lnk"/>
          </rescap3:DesktopAppMigration>
        </rescap3:Extension>
      </Extensions>
    </Application>
  </Applications>

那么,如何在开始菜单或桌面快捷方式的快捷方式中添加该命令参数?

由于参数将在清单中进行硬编码,因此您最好更改 launcher.exe 的代码,以在它作为打包应用程序启动时采用“--param”。

如果您不能更改该二进制文件的代码,您可以在您的包中添加第二个 EXE,例如 helper.exe,将其设为入口点,然后启动 launcher.exe从那里获得所需的参数。

这是 helper.exe 的代码片段:

static void Main(string[] args)
{
    string result = System.Reflection.Assembly.GetExecutingAssembly().Location;
    int index = result.LastIndexOf("\");
    string processPath = $"{result.Substring(0, index)}\..\Launcher\Launcher.exe";
    Process.Start(processPath, "--param");
}

此处上传了完整的示例项目:https://1drv.ms/u/s!AovTwKUMywTNnY4ofULXFV778Dtdxw

您可能还会发现这篇有点相关的博文很有帮助: https://blogs.msdn.microsoft.com/appconsult/2017/06/23/accessing-to-the-files-in-the-installation-folder-in-a-desktop-bridge-application/

专业版desktop bridge support from Advanced Installer可以自动管理AppX包的快捷方式参数。 (该应用程序自动包含一个存根 EXE,它获取您的参数并将它们传递给您的主应用程序 EXE)。

它还可以导入您的 AppX 包,因此您不必从头开始创建项目。导入完成后,您最终会在 Advanced Installer 中创建一个项目,从中可以创建 AppX 和 MSI(例如为 Win7 用户提供服务)。

它还有一个 VS 扩展,使构建和调试更加容易,您可以在上面链接页面的视频中看到它的实际效果。

免责声明:我在 Advanced Installer 团队中工作。