Running an EXE with parameters after installation of the files using WIX - wix

I have this installer through which I'm installing Mosquitto as a re-requisite for my system. But after installation I need to run the EXE passing two parameters. The command to run would be "mosquitto -v -c mosquitto.conf". I tried to do this using the following command but nothing happens.
<Property Id="WixShellExecTarget" Value="[mosquitto.exe] -v -c mosquitto.conf" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="RunMosquitto" Before="InstallFinalize" />
</InstallExecuteSequence>
what is the right way to do this? Also I need to stop this EXE during uninstallation. How can I do that as well? Any help would be much appreciated. Thanks.

No, according to this WiX mailing list archive.
Bob Arnson, one of the WiX developers, said the following:
WixShellExecTarget must be only the path of the executable/document.
There's no support to add arguments. For that, use a "normal" exe custom
action instead of WixShellExec.

Related

Accessing variable in Wix CustomAction ExecCommand

I have a custom action in my WiX script to copy installation log:
<CustomAction Id="CopyLogFile" Execute="immediate"
ExeCommand="cmd /c copy [MsiLogFileLocation] "\"[APPLICATIONFOLDER]Install.log\"""
Directory="TARGETDIR"
Impersonate="no"
Return="asyncNoWait" />
<InstallExecuteSequence>
<Custom Action="CopyLogFile" OnExit="success" />
</InstallExecuteSequence>
The problem is the APPLICATIONFOLDER environment variable. No matter how I try to use it it does not work. I tried single &quot, double &quot, no &quot, etc. Nothing helps.
If I hard-code the destination like this:
ExeCommand="cmd /c copy [MsiLogFileLocation] c:\temp\Install.log"
it works fine.
However, I need to copy the install log to some known location on the user's machine.
I looked at WiX CustomAction ExeCommand failing?, and Not able to send Wix SourceDir path with spaces to custom action ExeCommand but it does not help with this issue.
According to Windows Installer Formatted reference your commandline should be:
cmd /c copy [MsiLogFileLocation] "\"[%APPLICATIONFOLDER]Install.log\""
^
You are missing the % prefix for environment variables.

Elevated custom action before removing files

I'm trying to write an Installer for my Windows Service using WiX. My executable can register/unregister itself as a Windows Service using the command line parameters --install and --uninstall. This is what I came up with:
<CustomAction Id='InstallAsService' FileKey='CCWirelessServer.exe' ExeCommand='--install' Return='check' Impersonate='no' Execute='deferred' />
<CustomAction Id='InstallAsServiceRollback' FileKey='CCWirelessServer.exe' ExeCommand='--uninstall' Return='check' Impersonate='no' Execute='rollback' />
<CustomAction Id='UninstallAsService' FileKey='CCWirelessServer.exe' ExeCommand='--uninstall' Return='check' Impersonate='no' Execute='deferred' />
<InstallExecuteSequence>
<Custom Action='InstallAsService' After='InstallFiles' >NOT Installed</Custom>
<Custom Action='InstallAsServiceRollback' Before='InstallAsService' >NOT Installed</Custom>
<Custom Action='UninstallAsService' Before='RemoveFiles' >Installed</Custom>
</InstallExecuteSequence>
Both install and uninstall basically work. But during uninstall I get the following message:
The setup must update files or services that cannot be updated while the system is running. If you choose to continue, a reboot will be required to complete the setup.
Despite this error message, the service gets unregistered and the files are deleted without a reboot. To me this looks like the installer is checking if CCWirelessServer.exe is opened before it executes my custom action.
So my question is: How do I need to modify my install execute sequence so that this error message does no longer appear?
If you are developing for Windows Installer > 3.1 you can take a look at the MSIRESTARTMANAGERCONTROL-property to see if it it set properly or if other values would would stop displaying the message.
I could suppress the message using the following values:
<Property Id="MSIRESTARTMANAGERCONTROL" Value="Disable" Secure="yes" />

Is it possible to have a batch file as a binary element type in Wix?

Here's my wix
<Binary Id="B.RenameFiles" SourceFile="RenameFiles.bat"/>
<CustomAction Id="CA.RenameFiles" BinaryKey="B.RenameFiles"
ExeCommand="RenameFiles.bat" Execute="immediate" Return='ignore'/>
<InstallExecuteSequence>
<Custom Action="CA.RenameFiles" Before="InstallValidate"></Custom>
</InstallExecuteSequence>
This doesn't work and spits out an error in the msi log "A program required for this install to complete could not be run". I'm not really sure if this is possible or if binary is only for use with exe's and dll's etc.
The way i'm doing it at the moment is to install the bat file and then run it from there but it would be neater if I could use it as a binary instead and not install it on the local machine.
Thanks
Neil
BAT files cannot be launched directly by Windows Installer custom actions. You need a custom action which uses ShellExecute to launch your BAT.
So you can't use a BAT as a Binary custom action.
Agree with Cosmin, you cannot execute BAT from binary, however you can launch it (almost) at any time during installation with help of "CMD.exe /C " custom action, and even have it run hidden (without cmd.exe window), i.e. for deffered CA one can use:
<CustomAction Id="Set_CA_HiddenBAT" Property="CA_HiddenBAT" Value=""cmd.exe" /c "[DirectoryWhereBatFileInstalled]Your.bat"" />
<CustomAction Id="CA_HiddenBAT" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="ignore" Impersonate="yes" />
Or if you want it visible:
<CustomAction Id="CA_LaunchBAT" Directory="DirectoryWhereToExecute" ExeCommand="CMD.exe /c "[DirectoryWhereBatFileInstalled]Your.bat"" Return="ignore" />
Note: Remember to run CA_HiddenBAT / CA_LaunchBAT after InstallFiles action and have added WixUtilExtension to your .wixproj:
<LinkerAdditionalOptions>-ext WixUtilExtension</LinkerAdditionalOptions>
<CompilerAdditionalOptions>-ext WixUtilExtension</CompilerAdditionalOptions>
There's also a way to launch BAT before InstallFile action, but this is tricky, let me know if you need this.

Wix CustomAction to run only in basic mode

My wix 3.5 setup can be downloaded and run in normal installation situation. I also use the same msi for updates and call msiexec with /qb (basic quiet interface) from within the app itself.
All is ok up to here. In normal setups, I have an option to start app upon install (taken from tutorial) and works fine.
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Start $(var.AppName) $(var.ExeVersion) now..." />
<Property Id="WixShellExecTarget" Value="[#$(var.AppName).exe]" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
I want my update to be quiet and start the updated app after successfull install. In order to do this I have a custom action like this in my InstallExecuteSequence:
<InstallExecuteSequence>
<RemoveExistingProducts After="InstallFinalize"/>
<Custom Action="LaunchApplication"
After="RemoveExistingProducts"/>
</InstallExecuteSequence>
This is also ok too, however obviously, now my app is automatically started with normal (not /qb) setups. In order to overcome this, I suppose I need to detect in which UILevel I am and run the custom action only in INSTALLUILEVEL_BASIC.
So here is my question: How can I detect the UILevel in InstallExecuteSequence or CustomAction? Or is there a way to run CustomAction only in quiet basic mode in Wix.
You should condition condition the custom action by UILevel = 3

Start application after installation

I've googled around and found some topics like
http://wix.sourceforge.net/manual-wix3/run_program_after_install.htm
and
Launch application after installation complete, with UAC turned on
but, i don't use any ui. Just simple installation!
So far
<CustomAction Id="LaunchApp" Directory="INSTALLDIR" ExeCommand="[SystemFolder]cmd.exe /C MyExe.exe" />
<InstallExecuteSequence>
<RemoveExistingProducts Before="InstallInitialize" />
<Custom Action="LaunchApp" After="InstallFinalize" />
</InstallExecuteSequence>
but when i start the installer, a window pops up: "Please wait while Windows configures MyProgram". and on top of it comes cmd.exe just with a blinking cursor, when i close cmd i get message :"There is a problem with this Windows Installer package. A program required for this install to complete could not be run." Though program remains opened.
How can i do that properly (without any UI)?
Thanks in advance!
What happens if you use
ExeCommand="[SystemFolder]cmd.exe /C start MyExe.exe"
Set Return to asyncNoWait for your custom action. This way the custom action runs and the installer doesn't wait for it or check its return code.
I had the problem that it also tried to run at uninstallation.. This way it runs only on installation, reparation and updating (changing)
<CustomAction Id="LaunchApp" Directory="INSTALLFOLDER" ExeCommand="[SystemFolder]cmd.exe /C start MyFile.exe" />
<InstallExecuteSequence>
<Custom Action="LaunchApp" After="InstallFinalize">NOT REMOVE</Custom>
</InstallExecuteSequence>
Information about NOT REMOVE could be found here: https://stackoverflow.com/a/17608049/9758687