Is there a way to run uninstallers from an installer in WiX? - wix

I have a WiX based installer for a suite of applications. It replaces a bunch of old installers where each application in the suite had its own InstallShield based installer.
I would like the WiX installer to find any old InstallShield based installations and run their respective uninstallers. I have tried this:
<Property Id="OLD_APPLICATION_A_UNINSTALLSTRING">
<RegistrySearch Id="OldAppAUninstallString" Root="HKLM"
Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{$(var.OldAppAInstallerGUID)}"
Name="UninstallString" Type="raw"/>
</Property>
<InstallExecuteSequence>
<Custom Action="UninstallAppA" Before="InstallInitialize">
NOT Installed AND OLD_APPLICATION_A_UNINSTALLSTRING
</Custom>
</InstallExecuteSequence>
<CustomAction Id="UninstallAppA" Directory="System32"
ExeCommand="[OLD_APPLICATION_A_UNINSTALLSTRING] /qn" Execute="immediate" Return="check"/>
This results in a failed installation and error status 1618: "Another installation is already in progress. Complete that installation before proceeding with this install." Only one other installation is in progress, this installation...
Is there a way to run uninstallers from an installer in WiX?
I also have a bootstrapper and maybe I should run these uninstallations from there somehow. But I want to run them as late as possible in case the user cancels the installation. If that happens it doesn't look too good if the old application suite is gone...

In MSI there is a mutex that prevents two installation transactions (execute sequence) running at the same time hence your error.
You can use additional Upgrade elements to seek them out by UpgradeCode / Version / Lanugage and cause their removal during your installation transaction.

Related

VC redistributable fails to install when executed within an MSI [duplicate]

I have an application compiled in VS 2015 and requires the VC++ Redistributable package in order to run properly. Prior to this latest build, we were using an older version of VS and simply used a merge module to handle the installation of the appropriate redist files. However, I noticed that when using the latest version of the merge modules for 2015 (Microsoft_VC140_CRT_x64.msm) that my application still wouldn't work out of the box. I did some digging and it appears that some things have changed with the latest version of the merge modules. It appears that Microsoft is now recommending to install the vcredist_x64.exe package directly instead of using merge modules.
So, I'm attempting to create a custom action to do this. I'm following a similar tutorial here, although adapting it for the VC Redistributable executable. The first thing I need to do is setup where the .exe file is going to be placed once installed:
<Directory Id='APPLICATIONROOTDIRECTORY' Name='MyApp'>
<Directory Id="VCREDISTDIR" Name="VCRedist">
</Directory>
</Directory>
Then, I need to add my files into a component group which will be installed as part of a hidden feature (as I want this to be automatically installed).
<ComponentGroup Id="VCRedist" Directory="VCREDISTDIR">
<Component Id="vcredist_x64.exe" Guid="-INSERT-GUID-HERE-" Win64="yes">
<File Id="VCREDISEXE" Name="vcredist_x64.exe" KeyPath="yes" Source="$(var.VCRedistSourceDir)" Checksum="yes"></File>
</Component>
</ComponentGroup>
And...
<Feature Id="VCRedistributable" Title="Visual C++ Runtime" AllowAdvertise="no" Display="hidden" Level="1">
<ComponentGroupRef Id="VCRedist" />
</Feature>
At this point, the vcredist_x64.exe should be copied to the end user's machine. Now, I need to create a custom action to launch the executable after the installation.
<CustomAction Id="InstallVCRedistributable"
FileKey="VCREDISEXE"
Execute="deferred"
ExeCommand="/silent"
Impersonate="no"
Return="check"/>
<InstallExecuteSequence>
<Custom Action="InstallVCRedistributable" Before="InstallFinalize">
<![CDATA[NOT REMOVE]]>
</Custom>
</InstallExecuteSequence>
I also include a status message to my UI so that I can see when the executable is being executed.
<UI>
<ProgressText Action="InstallVCRedistributable">Installing Visual C++ Redistributable for Visual Studio 2015</ProgressText>
</UI>
Now, when I run my installer it should launch the vcredist_x64.exe... and it does... but then during the installation of that executable it gets hung up. I get a popup message that says there is a problem with this Windows Installer Package and that a program run as part of the setup did not complete. It then rolls-back my main application installation and never gets installed. Can anyone explain why this is happening and how to fix it? Thanks!
I found this question and tried it myself, being in the same situation. I found the installer error you're running into was/is Error 1618: "Another installation is already in progress." It seems that running the vc_redist installer inside your own installer simply won't work.
Your other options seem to be creating a bootstrapper as Patrick Allwood suggests above, or simply asking users to install the vc_redist package on their own before running your own installer. You can detect if the Universal C Runtime is already present by checking for ucrtbase.dll in C:\Windows\System32:
<Property Id="UCRTINSTALLED">
<DirectorySearch Id="UCRTSystemSearch" Path="[WindowsFolder]System32" Depth="0">
<FileSearch Id="UCRTFileSearch" Name="ucrtbase.dll" MinVersion="10.0.10240.16389" />
</DirectorySearch>
</Property>
If you only have a 32-bit installer, you can also use the [SystemFolder] property directly.
EDIT: As Kevin Smyth mentioned, the version of ucrtbase.dll is giving weird issues - reporting version 2.X to some tools, and version 10.Y to other tools. You can remove the MinVersion property if you just want to check for the existence of ucrtbase.dll.
I think the correct approach to take when having prerequisites that have their own installers is to create a WiX bootstrapper bundle, which runs through each installer in turn. This handles things like rollbacks on install failures, etc, which running custom actions from within an installer does not.
A barebones sample can be seen here, you add <MsiPackage> and <ExePackage> in the Chain element in the order you need them to install.
I was facing a similar problem (fully described in this closed question, which actually redirected me here). I was able to solve it, inspired by this entry about running the application after setup.
The key part is basically to add a final step to the UI that launches the vcredist installer:
<UI Id="UI_Main">
<!-- ...... -->
<Publish Dialog="ExitDialog"
Control="Finish"
Event="DoAction"
Value="InstallVCRedistributable">1</Publish>
</UI>
Regarding the custom action:
<CustomAction Id="InstallVCRedistributable"
FileKey="VCREDISEXE"
ExeCommand="/install /passive /norestart"
Impersonate="yes"
Return="asyncNoWait" />

How do you install VS Tools For Office Runtime from my WiX installer? I'm getting "waiting for another install to complete" deadlock

I'm writing an installer for my Office Outlook add-in using WiX. The add-in itself requires VS Tools For Office Runtime to be installed. So I thought to install it as a custom-action from within my own WiX installer:
<Binary Id='idBinVstorRedist' SourceFile='Sources\vstor_redist.exe' />
<CustomAction Id="idCSVstorRedist" Return="asyncWait" HideTarget="no" Execute="deferred" Impersonate="no" ExeCommand="" BinaryKey="idBinVstorRedist" />
<InstallExecuteSequence>
<Custom Action="idCSVstorRedist" After="InstallInitialize">
NOT Installed
</Custom>
</InstallExecuteSequence>
where the vstor_redist.exe itself is part of my MSI package:
But when I run my installer it deadlocks in the VstorRedist with the message: "Waiting for another install to complete":
What am I doing wrong here?
To check whether the VSTO Office Runtime is installed, we’ll add condition and two RegistrySearch elements. RegistrySearch, does exactly what the name implies, it searches the target machines’ registry for a specific key and value.
<Property Id="VSTORUNTIMEREDIST">
<RegistrySearch
Id="VSTORuntimeRedist"
Root="HKLM"
Key="SOFTWARE\Microsoft\VSTO Runtime Setup\v4R"
Name="Version"
Type="raw" />
</Property>
<Condition
Message="The Visual Studio 2010 Tools for Office Runtime is not installed.
Please download and install from
http://www.microsoft.com/en-us/download/details.aspx?id=20479.">
<![CDATA[Installed OR VSTORUNTIMEREDIST>="10.0.30319"]]>
</Condition>
Read more about that in the Creating WiX installation projects for VSTO-based Office add-ins article.
Also, you may find the How do you use WiX to deploy VSTO 3.0 addins? article helpful.
It may be due to the fact that your custom action is set to run After="InstallInitialize". I'm trialing running a batch script to install the runtime after checking if it isn't present or not and it appears to be working okay for me like this
<InstallExecuteSequence>
<Custom Action="RunBatch" Before="InstallFinalize"/>
</InstallExecuteSequence>
<CustomAction Id="RunBatch"
Execute="deferred"
Return="ignore"
Impersonate="no"
ExeCommand=""[SystemFolder]cmd.exe" /C "[INSTALLFOLDER]vsto_runtime.bat""
Directory="INSTALLFOLDER"/>
This is not the recommended way to install prerequisites but after having issues with creating a bundle, this is a working short term fix for me
Hopefully this is of some use for you.

Can Windows installer install two msi files at the same time? [duplicate]

This question already has answers here:
Wix and .NET Framework (prerequisites)
(5 answers)
Closed last month.
I have a msi installation package made by WIX, which automatically installs IIS Express 10.0 after the installation.
<Binary Id="myCustomActionsDLL" SourceFile="$(var.CustomAction.TargetDir)CustomAction.CA.dll" />
<CustomAction Id="CheckIISExpressStatus" BinaryKey="myCustomActionsDLL" DllEntry="CheckIISExpressStatus" Execute="immediate" Return="check" Impersonate="yes"/>
<CustomAction Id="InstallIISExpress" BinaryKey="myCustomActionsDLL" DllEntry="InstallIISExpress" Execute="immediate" Return="ignore" Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="CheckIISExpressStatus" After="InstallFinalize" Overridable="yes">NOT Installed</Custom>
<Custom Action="InstallIISExpress" After="CheckIISExpressStatus" Overridable="yes">NOT Installed AND IS_INSTALL_IISEXPRESS="1"</Custom>
</InstallExecuteSequence>
In the InstallIISExpress action, I call bat to perform the installation.
msiexec /i iisexpress_amd64_en-US.msi /qb
But during execution, the Windows Installer prompts the error:
Other programs are being installed, please wait for the installation to complete, and then try again to install the software.
What parameters can I set to allow msi to install two msi at the same time?
You must not run other setups from a custom action within your main MSI. Instead you should run MSI files in sequence using a bootstrapper such as WiX's Burn feature.
It is late. I tried to write a proper explanation of this at one point, maybe see if it makes sense to you: Wix - How to run/install application without UI.
To summarize: running legacy setup.exe files from a custom action in your MSI will not be reliable, and running MSI files - whether directly or embedded in a setup.exe will positively not work because Windows Installer does not allow concurrent MSI installation sequences. A mutex is set when InstallExecuteSequence runs, and no other InstallExecuteSequence can be run while it is in effect. Concurrent MSI installations are forbidden and technically impossible.

how to integrate third party installation along with current installer in wix?

I am trying to install visual c++ 2013 along with my installer in wix.
for that i am using custom installation like
<Binary Id="vcredist_x862013.exe" SourceFile="D:\Projects\vcredist_x862013.exe"/>
<CustomAction Id="Launchvc2013" BinaryKey="vcredist_x862013.exe" ExeCommand="" Execute='deferred' Return='asyncNoWait' Impersonate='no'/>
<InstallExecuteSequence>
<Custom Action='Launchvc2013' Before='InstallFinalize'>NOT Installed AND NOT REMOVE</Custom>
</InstallExecuteSequence>
currently if the user installs or didnt install vc2013 as part of installation the setup will continue.
is it possible to make it like, the set up should fail if user cancel visual c++ installtion?
Yes it possible, you need to use bootstrapper for that.
Use this blog by Heath Stewart to get you started.

WIX run vcredist_x64.exe on install

I have an application compiled in VS 2015 and requires the VC++ Redistributable package in order to run properly. Prior to this latest build, we were using an older version of VS and simply used a merge module to handle the installation of the appropriate redist files. However, I noticed that when using the latest version of the merge modules for 2015 (Microsoft_VC140_CRT_x64.msm) that my application still wouldn't work out of the box. I did some digging and it appears that some things have changed with the latest version of the merge modules. It appears that Microsoft is now recommending to install the vcredist_x64.exe package directly instead of using merge modules.
So, I'm attempting to create a custom action to do this. I'm following a similar tutorial here, although adapting it for the VC Redistributable executable. The first thing I need to do is setup where the .exe file is going to be placed once installed:
<Directory Id='APPLICATIONROOTDIRECTORY' Name='MyApp'>
<Directory Id="VCREDISTDIR" Name="VCRedist">
</Directory>
</Directory>
Then, I need to add my files into a component group which will be installed as part of a hidden feature (as I want this to be automatically installed).
<ComponentGroup Id="VCRedist" Directory="VCREDISTDIR">
<Component Id="vcredist_x64.exe" Guid="-INSERT-GUID-HERE-" Win64="yes">
<File Id="VCREDISEXE" Name="vcredist_x64.exe" KeyPath="yes" Source="$(var.VCRedistSourceDir)" Checksum="yes"></File>
</Component>
</ComponentGroup>
And...
<Feature Id="VCRedistributable" Title="Visual C++ Runtime" AllowAdvertise="no" Display="hidden" Level="1">
<ComponentGroupRef Id="VCRedist" />
</Feature>
At this point, the vcredist_x64.exe should be copied to the end user's machine. Now, I need to create a custom action to launch the executable after the installation.
<CustomAction Id="InstallVCRedistributable"
FileKey="VCREDISEXE"
Execute="deferred"
ExeCommand="/silent"
Impersonate="no"
Return="check"/>
<InstallExecuteSequence>
<Custom Action="InstallVCRedistributable" Before="InstallFinalize">
<![CDATA[NOT REMOVE]]>
</Custom>
</InstallExecuteSequence>
I also include a status message to my UI so that I can see when the executable is being executed.
<UI>
<ProgressText Action="InstallVCRedistributable">Installing Visual C++ Redistributable for Visual Studio 2015</ProgressText>
</UI>
Now, when I run my installer it should launch the vcredist_x64.exe... and it does... but then during the installation of that executable it gets hung up. I get a popup message that says there is a problem with this Windows Installer Package and that a program run as part of the setup did not complete. It then rolls-back my main application installation and never gets installed. Can anyone explain why this is happening and how to fix it? Thanks!
I found this question and tried it myself, being in the same situation. I found the installer error you're running into was/is Error 1618: "Another installation is already in progress." It seems that running the vc_redist installer inside your own installer simply won't work.
Your other options seem to be creating a bootstrapper as Patrick Allwood suggests above, or simply asking users to install the vc_redist package on their own before running your own installer. You can detect if the Universal C Runtime is already present by checking for ucrtbase.dll in C:\Windows\System32:
<Property Id="UCRTINSTALLED">
<DirectorySearch Id="UCRTSystemSearch" Path="[WindowsFolder]System32" Depth="0">
<FileSearch Id="UCRTFileSearch" Name="ucrtbase.dll" MinVersion="10.0.10240.16389" />
</DirectorySearch>
</Property>
If you only have a 32-bit installer, you can also use the [SystemFolder] property directly.
EDIT: As Kevin Smyth mentioned, the version of ucrtbase.dll is giving weird issues - reporting version 2.X to some tools, and version 10.Y to other tools. You can remove the MinVersion property if you just want to check for the existence of ucrtbase.dll.
I think the correct approach to take when having prerequisites that have their own installers is to create a WiX bootstrapper bundle, which runs through each installer in turn. This handles things like rollbacks on install failures, etc, which running custom actions from within an installer does not.
A barebones sample can be seen here, you add <MsiPackage> and <ExePackage> in the Chain element in the order you need them to install.
I was facing a similar problem (fully described in this closed question, which actually redirected me here). I was able to solve it, inspired by this entry about running the application after setup.
The key part is basically to add a final step to the UI that launches the vcredist installer:
<UI Id="UI_Main">
<!-- ...... -->
<Publish Dialog="ExitDialog"
Control="Finish"
Event="DoAction"
Value="InstallVCRedistributable">1</Publish>
</UI>
Regarding the custom action:
<CustomAction Id="InstallVCRedistributable"
FileKey="VCREDISEXE"
ExeCommand="/install /passive /norestart"
Impersonate="yes"
Return="asyncNoWait" />