Wix - How to run exe files after installation from installed directory?
Asked Answered
S

2

31

I'm using a program which is being installed using wix. (Don't know if it's relevant but it's a C# program)

I want to run an exe file which was installed by the msi file, but the location of the installation is unknown to me since the user chooses the installation path.

I wanted to ask for example of how to run an exe file from the location the user chooses.

Even though it's not a part of the question, I would also be glad to see some example of running an exe file from an absolute location since I'm a beginner to wix and doing it all for the first time.

Simonides answered 9/10, 2013 at 12:20 Comment(0)
D
53

The Isaiah4110 answer is not the best way if you don´t need a UI.

The simplest way to execute the exe file target you are installing through the MSI file produced by WiX is with a custom action type 18 (identifying the action by FileKey/FileRef), here you are a complete examples for v3/v4:

WiX v3:

<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
    <Component Id="TargetProgram" Guid="f757ff43-0266-483a-8749-ec796cba4b25" >
        <File Id="EXE" Source="C:\SetupProject\Includes\TargetProgram.exe" />
    </Component>
</ComponentGroup>

<CustomAction Id="EXECUTE_AFTER_FINALIZE"                  
              Execute="immediate" 
              Impersonate="no"
              Return="asyncNoWait"
              FileKey="EXE"
              ExeCommand="" />

<InstallExecuteSequence>
    <Custom Action="EXECUTE_AFTER_FINALIZE" After="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
</Fragment>

WiX v4:

<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
    <Component Id="TargetProgram" Guid="f757ff43-0266-483a-8749-ec796cba4b25" >
        <File Id="EXE" Source="C:\SetupProject\Includes\TargetProgram.exe" />
    </Component>
</ComponentGroup>

<CustomAction Id="EXECUTE_AFTER_FINALIZE"                  
              Execute="immediate" 
              Impersonate="no"
              Return="asyncNoWait"
              FileRef="EXE"
              ExeCommand="" />

<InstallExecuteSequence>
    <Custom Action="EXECUTE_AFTER_FINALIZE" After="InstallFinalize" Condition="NOT Installed" />
</InstallExecuteSequence>
</Fragment>
Disguise answered 30/8, 2018 at 8:40 Comment(8)
This was perfect, thank you! Not sure why everyone assumes you want a full blown UI when running a file after install or giving the user the option. This way works with and WITHOUT UI so this should be the universal answer.Hexahedron
Also good if you need to pass arguments to the EXE, which you can do in ExeCommandDais
Freaking Awesome! Just what I needed, works well... Thank You! IbaiBolo
This is the answer I have been looking for, for days. This gets me the unattended install and upgrades that I needed in a completely silent installer. Thank you.Tessie
After searching the internet for days finally this solved the problem for me!! I mixed the checkbox option with your custom action and it worked like charm.Debouchment
this will start your exe with the wrong working directory. You can remove FileKey and use Directory="INSTALLFOLDER" and ExeCommand="[INSTALLFOLDER]TargetProgram.exe" then the program will have it location as working directory. This is a type 34 custom action then. wixtoolset.org/documentation/manual/v3/xsd/wix/…Chrisman
The Impersonate="no" part may not be correct, unless one needs to run the executable in an elevated process. In most cases it should be set to "no", if one needs to run an application that was just installed on behalf of current user.Painful
I can confirm I followed this solution in WIXv4 and it works, though you will need to use FileRef instead of Filekey also instead of using Not installed between the tag use it inside with variable Condition, rest its working perfectly.Coin
F
15

This can be achieved with the help of the WIX Extensions. The bold/italic text below will handle the case of finding the exact location of your EXE :)

Step 1: Add the extension libraries to your project

If you are using WiX on the command-line you need to add the following to your candle and light command lines:

-ext WixUIExtension -ext WixUtilExtension

If you are using Visual Studio you can add the extensions using the Add Reference dialog:

Right click on your project in Solution Explorer and select Add Reference...
Select the WixUIExtension.dll assembly from the list and click Add
Select the WixUtilExtension.dll assembly from the list and click Add
Close the Add Reference dialog

Step 2: Add UI to your installer

The WiX Minimal UI sequence includes a basic set of dialogs that includes a finished dialog with optional checkbox. To include the sequence in your project add the following snippet anywhere inside the <Product> element.

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

To display the checkbox on the last screen of the installer include the following snippet anywhere inside the <Product> element:

<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch My Application Name" />

The WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT property is provided by the standard UI sequence that, when set, displays the checkbox and uses the specified value as the checkbox label.

Step 3: Include the custom action

Custom actions are included in a WiX project using the <CustomAction> element. Running an application is accomplished with the WixShellExecTarget custom action. To tell Windows Installer about the custom action, and to set its properties, include the following in your project anywhere inside the <Product> element:

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

The Property element sets the WixShellExecTarget to the location of the installed application. WixShellExecTarget is the property Id the WixShellExec custom action expects will be set to the location of the file to run. ***

The Value property uses the special # character to tell WiX to look up the full installed path of the file with the id myapplication.exe.


The CustomAction element includes the action in the installer. It is given a unique Id, and the BinaryKey and DllEntry properties indicate the assembly and entry point for the custom action. The Impersonate property tells Windows Installer to run the custom action as the installing user.

Step 4: Trigger the custom action

Simply including the custom action, as in Step 3, isn't sufficient to cause it to run. Windows Installer must also be told when the custom action should be triggered. This is done by using the <Publish> element to add it to the actions run when the user clicks the Finished button on the final page of the UI dialogs. The Publish element should be included inside the <UI> element from Step 2, and looks like this:

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

The Dialog property specifies the dialog the Custom Action will be attached to, in this case the ExitDialog. The Control property specifies that the Finish button on the dialog triggers the custom action. The Event property indicates that a custom action should be run when the button is clicked, and the Value property specifies the custom action that was included in Step 3. The condition on the element prevents the action from running unless the checkbox from Step 2 was checked and the application was actually installed (as opposed to being removed or repaired).

Check this link for details. How to run exe after install. I copied it here for the benefit of others looking for the same answer.

Frith answered 9/10, 2013 at 14:9 Comment(2)
When I try this the installer never exists. When you try to close the installer it launches a new app every time you click close but it never exits.Upstage
How to pass command line parameter to the exe using this method? @FrithPresidium

© 2022 - 2024 — McMap. All rights reserved.