Search code examples
wixcustom-action

WIX Installer - Possible to Invoke Custom Action .exe Before `InstallFiles`?


I have an .exe embedded inside my MSI installer which I'd like to somehow call directly from the installer, before the the 'InstallFiles' action occurs.

It's defined as follows:

<CustomAction Id="LaunchInstallManager_TryUninstall" Return="ignore" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="&quot;[#fil713F8F6A7BC9B98857D779B9B29873E1]&quot; /someargument"></CustomAction>

<Custom Action="LaunchInstallManager_TryUninstall" Before="InstallFiles">NOT Installed</Custom>

But upon looking at the logs, it looks like it's (trying to be) called from the install destination.

Is such a thing possible?


Solution

  • It is possible, but in a different way. The 'run EXE' type of custom action will always search for the executable on the target system. Thus, if your executable is installed along with your app, it is not an option.

    Here is another way:

    • First, author your EXE as a <Binary> instead.

      It is as easy as <Binary Id="MyEXE" SourceFile="PATH\TO\EXE" />.

    • Add a DLL deferred custom action, which will extract the binary, run it with parameters and clean up afterwards.

      This post can give you an idea how to extract the binary using C# and DTF. Besides, in case you need to pass parameters, make sure you do it the right way for deferred custom action.

    Finally, remember that each deferred custom action (that is the one to change the target system) must have corresponding rollback action. This article might give you some hints on how to test the direct and rollback behaviors of your custom actions.