Search code examples
wixwindows-installer

Launching application on installer completion not working in user mode


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.


Solution

  • 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]" />