在安装程序完成时启动应用程序在用户模式下不起作用

Launching application on installer completion not working in user mode

我正在创建一个带有复选框的双模式安装程序,让用户在安装后启动应用程序。

在机器范围内安装(管理员模式)后,应用程序会按预期启动。

当仅为用户安装(非管理员模式)时,应用程序无法启动:

Action ended 9:04:52: LaunchApplication. Return value 3.
MSI (c) (F0:94) [09:04:52:151]: Note: 1: 2205 2:  3: Error 
MSI (c) (F0:94) [09:04:52:151]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2896 
DEBUG: Error 2896:  Executing action LaunchApplication failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: LaunchApplication, , 

我看过 也有同样的错误,但我的文件名已经放在方括号中了:

<Property Id="WixShellExecTarget" Value="[#FILE_SweetApp.WPF.exe]" />

有什么想法吗?


编辑

这是相关代码:

<?define MyPath="$(var.SolutionDir)MyApp.WPF\bin$(var.Configuration)"?>

<ComponentGroup Id="MyApp.WPF"  Directory="APPLICATIONFOLDER">
    <Component Id="MainExecutable" Guid="{my guid}">
        <File Id="FILE_App.WPF.exe" Source="$(var.MyPath)\myapp.exe" />
    </Component>
    ...
</ComponentGroup>

<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch app when setup exits." />
<Property Id="WixShellExecTarget" Value="[#FILE_App.WPF.exe]" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />

<UI>
  <Publish Dialog="ExitDialog" Control="Finish" Order="1" Event="DoAction" Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT installed</Publish>
</UI>

编辑 2

虽然在安装程序完成时启动应用程序不适用于全新的应用程序安装,但奇怪的是它在我更新应用程序时有效。

我认为这可能与 .NET 版本有关,因为 this blog 似乎与我有相同的症状。根据那个 post 自定义操作的空参数是转移注意力,因为自定义操作很可能甚至 运行.

Best Guess: Without seeing the source it is hard to guess what is wrong. I would say you probably have a mismatching reference between the WixShellExecTarget property value and the File Id of the file to launch?:

<..>

<Property Id="WixShellExecTarget" Value="[#MyFile.exe]" />

<..>

<File Id="MyFile.exe" Source="C:\MyFile.exe">

<..>

WiX 文档:WiX 文档中有一个示例:WiX sample for application launch(供其他人将来参考).

Mock-Up样本:这里是基于上述link的样本。您必须首先:(1) 创建新的 WiX 3 项目,2) 添加对 [= 的引用16=]WixUtilExtension.dll:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

<!--NOTE #1: Add an UpgradeCode GUID below -->

  <Product Id="*" Name="WiX Dialog Testing" Language="1033" Version="1.0.0.0"
           Manufacturer="Hobbit" UpgradeCode="PUT-GUID-HERE">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <UI>
      <UIRef Id="WixUI_Advanced" />

      <!-- Folder redirect dialog events -->
      <Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="1" Order="3">WixAppFolder = "WixPerUserFolder"</Publish>
      <Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="{}" Order="2">WixAppFolder = "WixPerMachineFolder"</Publish>
      <Publish Dialog="InstallScopeDlg" Control="Next" Event="DoAction" Value="WixSetDefaultPerMachineFolder" Order="3">WixAppFolder = "WixPerMachineFolder"</Publish>
      <Publish Dialog="InstallScopeDlg" Control="Next" Event="DoAction" Value="WixSetDefaultPerUserFolder" Order="3">WixAppFolder = "WixPerUserFolder"</Publish>

      <!-- Launch application dialog event -->
      <Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
    </UI>

    <!-- Launch application constructs NOTE! Added 'Secure="yes"' -->
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch My Application Name Test" Secure="yes" />
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1" Secure="yes" /> <!-- Checked by default = 1 -->

<!--NOTE #2: Make Value match File Id in component / file entry below -->

    <Property Id="WixShellExecTarget" Value="[#MyFile.exe]" />
    <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />

    <!-- Folder redirect constructs -->
    <Property Id="ApplicationFolderName" Value="PerUserPerMachine" />
    <Property Id="WixAppFolder" Value="WixPerMachineFolder" />

    <Feature Id="ProductFeature" Title="WiX Dialog Testing" Level="1" />

    <Directory Id="TARGETDIR" Name="SourceDir">

      <Directory Id="DesktopFolder" />
      <Directory Id="ProgramFilesFolder">

<!--NOTE #3: Make sure Directory Id is APPLICATIONFOLDER -->

        <Directory Id="APPLICATIONFOLDER" Name="WiX Dialog Testing">

<!--NOTE #4: Add a component GUID below, adjust source file path, set File Id -->

            <Component Feature="ProductFeature" Guid="PUT-GUID-HERE">
              <File Id="MyFile.exe" Source="C:\MyFile.exe">
                <Shortcut Id="AppDesktopShortcut" Name="WiX Dialog Testing" Directory="DesktopFolder"  />
              </File>
              <RegistryValue Root="HKCU" Key="Software\My Company\My Product" Name="installed" Type="integer" Value="1" KeyPath="yes" />
            </Component>

        </Directory>
      </Directory>
    </Directory>

  </Product>

</Wix>

问题是 #FILE_App.WPF.exe 值。

<Property Id="WixShellExecTarget" Value="[#FILE_App.WPF.exe]" />

对于每个用户的新安装值是:

%userprofile%\AppData\Local\Programs\MySweetApp\MySweet.exe

而不是实际安装位​​置:

%userprofile%\AppData\Local\Apps\MySweetApp\MySweet.exe

因此 LaunchApplication 自定义操作无法找到 .exe 并失败。

解决方案是使用正确的 .exe 位置创建自定义 属性 (ExeLocation),并将其用于自定义操作:

<Property Id="WixShellExecTarget" Value="[ExeLocation]" />