1

I'm creating a dual mode installer with a checkbox to let the user start the application after installation.

When installed machine wide (admin mode) the app launches as expected.

When installed just for the user (non admin mode) the app does not launch:

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

I've had a look at this question which has the same error, but I already have my file name in square brackets:

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

Any ideas?


Edit

This is the relevant code:

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

Edit 2

Although launching the app on installer completion does not work on fresh app installs, strangely enough it works when I'm updating the app.

I think it might be .NET version related, as this blog seems to have the same symptoms I'm having. According to that post the empty arguments to the custom action are red herrings, as the custom action most likely doesn't even run.

Felix
  • 3,783
  • 5
  • 34
  • 53
  • The log file should tell you more, but it looks like it just has an empty string for argument? For one thing you can change the last part of the condition to be **`Installed`** and not **`installed`**. Try that first and see if that matters. – Stein Åsmul Jun 04 '19 at 23:50
  • No luck changing to **`Installed`**. I think you're right, the argument is an empty string so naturally it doesn't know what to launch. – Felix Jun 05 '19 at 15:52
  • Unfortunately I couldn't get this to work. I ended up removing the checkbox. – Felix Jun 06 '19 at 16:17
  • While trying to remove the checkbox it suddenly started working :/ Same code, didn't even restart Visual Studio. I don't have a clue why it wasn't working... – Felix Jun 07 '19 at 17:57
  • Well that is odd indeed. You didn't change the package's bitness did you? (64-bit). Let us know if you discover what it was. Do you still have a malfunctioning MSI? You can diff them using Dark.exe or another MSI tool. I will update later. Heading out. – Stein Åsmul Jun 07 '19 at 18:32
  • [Comparing MSI files](https://stackoverflow.com/a/48482546/129130). There is also a section on using `dark.exe` (from the WiX toolkit) to disassemble an MSI file to WiX XML markup. If you disassemble a faulty MSI and a working MSI you can see if there are any code differences by diffing the `*.wxs` files. Or you can just diff the MSI files directly - which is easier. – Stein Åsmul Jun 07 '19 at 18:54
  • It must have been something to do with my machine. I have an MSI named "Install for user not auto launching.msi" from when this didn't work, and it works now :/ – Felix Jun 07 '19 at 21:16
  • Did you reboot? Did you run Windows Update perhaps? Just what comes to mind. Can't really see why that would cause this. There is something simple that we are missing. – Stein Åsmul Jun 07 '19 at 23:20
  • Nope, didn't reboot. Didn't even restart Visual Studio. I guess an automatic Windows Update could have happened? – Felix Jun 10 '19 at 16:55
  • What anti-virus do you use? You could check the logs. Should not be relevant since it launched with admin rights. Group policies can apply every hour or so - in case you are in an Active Directory environment (domain). I got nothing that makes sense I guess. Let us know if you discover why? – Stein Åsmul Jun 10 '19 at 17:07
  • To be honest I'm just happy that it works :) – Felix Jun 10 '19 at 18:34
  • Certainly. From experience: you can be sure it happens again :-). – Stein Åsmul Jun 10 '19 at 18:45
  • That will be a sad day! You'll undoubtedly hear from me again that day :) – Felix Jun 10 '19 at 18:47

2 Answers2

1

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 Documentation: There is a sample of this in the WiX documentation: WiX sample for application launch (for future reference for others).

Mock-Up Sample: Here is a sample based on the above link. You must first: (1) create new WiX 3 project, 2) add references to WixUIExtension.dll and 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>
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • I've added the code I think is relevant. What has got me confused is that it works when installed machine wide but not when installed for the user. When I hardcode the path for an .exe it works. I guess the path is wrong when installed for the user? But I thought `[#FILE_App.WPF.exe]` resolves to wherever that file gets installed? – Felix Jun 04 '19 at 22:38
  • See my other comment too (above). Could it be that you should try to use a different and simpler ID just to test? Try **`MyFile.exe`** instead. – Stein Åsmul Jun 04 '19 at 23:53
  • Before that try on a clean virtual and [check the log file if the file is actually scheduled for installation](https://learn.microsoft.com/en-us/windows/desktop/msi/checking-the-installation-of-features-components-files) during per-user installation. Check the [Formatted data type](https://learn.microsoft.com/en-us/windows/desktop/msi/formatted). – Stein Åsmul Jun 05 '19 at 00:01
  • Um, what's a clean virtual? A clean virtual machine? It looks like the file is scheduled for installation: `MSI (s) (68:B8) [09:04:46:780]: Component: MainExecutable; Installed: Absent; Request: Local; Action: Local`. And it must find the file, because I can launch the app from the start menu after installation. – Felix Jun 05 '19 at 16:04
  • No luck with simpler id of **`MyFile.exe`** :/ – Felix Jun 05 '19 at 16:27
  • I just tried your sample, and it also doesn't launch the app when I install for the local user only :/ Did it launch for you? – Felix Jun 05 '19 at 17:02
  • Got a place to dump the WiX markup from your adjusted sample from me? Maybe there is something wrong in there? Pastebin or somewhere? (I am away for a while). Are you testing as a standard or admin user? Try adding **`Secure="yes"`** to the two properties involved as shown in the updated WiX markup above. – Stein Åsmul Jun 05 '19 at 17:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/194508/discussion-between-felix-and-stein-asmul). – Felix Jun 05 '19 at 17:35
  • I'm back to trying to fix this issue :P I edited the question with my latest findings. – Felix Jul 23 '19 at 18:44
0

The issue was the #FILE_App.WPF.exe value.

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

For fresh per user installs the value was:

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

instead of the actual install location:

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

Hence the LaunchApplication custom action was not able to find the .exe and failed.

The solution was to create a custom property (ExeLocation) with the correct .exe location and use that for the custom action:

<Property Id="WixShellExecTarget" Value="[ExeLocation]" />
Felix
  • 3,783
  • 5
  • 34
  • 53