1

I made a Wix project that attemps to install a simple .txt example file. But, as a prerequisite, I want to uninstall a previous application.

To do so, I know msiexec allows you to uninstall a product by simply writing:

msiexec /x {PRODUCT_CODE}

on a command line.

Fortunately, I know this PRODUCT_CODE, so I tried to create a CustomAction to uninstall that product before the installation starts, like this:

<CustomAction Id="PropertyAssign" Property="SilentLaunch" Value="msiexec.exe /x {EA29682C-7DA1-441C-BF3E-702491F59258}" Execute="immediate" />
<CustomAction Id="SilentLaunch" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no" />

<InstallUISequence>
  <Custom Action="PropertyAssign" After="CostFinalize" />
  <Custom Action="SilentLaunch" After="PropertyAssign" />
</InstallUISequence>

But when I run the .msi, it says there was an unexpected error with code 2762 and exits installation.

I know the mistake is in that line, as if I erase it, everything goes ok.

Any idea on how to run that command line without any mistakes?

Sonhja
  • 8,230
  • 20
  • 73
  • 131

1 Answers1

3

The UI sequence should never make changes to the state of the machine. It should only gather, validate and report data to the user. All changes must be made in the execute sequence.

There is a mutex in Windows / MSI ( _MSIExecute ) that enforces one execute sequence per machine. Therefore you cannot call msiexec from an MSI. But what you can do is author a Major Upgrade rule to detect the other product and remove it. The Windows Installer standard action RemoveExisitingProducts can uninstall any MSI not just previous versions of yourself.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • I did an upgrade to previous versions that use good practices, but for those installations that don't follow good practices, I have to remove them by hand. So that's why I need to remove it by hand... Any idea? – Sonhja Sep 26 '13 at 11:01
  • Sorry, if I understood correctly I can't launc msiexec commands from a Wix installer. Is that what you say?http://stackoverflow.com/questions/8182560/uninstall-multiple-products-using-custom-action – Sonhja Sep 26 '13 at 11:06
  • Never from the execute sequence and only from the UI sequence if you want to violate several best practices and require the UI sequence to be elevated. The Upgrade table is the way to go. It can be used to tell MSI to remove other products in a way that follows all best practices. Otherwise you are going to need a setup.exe type bootstrapper/chainer to run your uninstall command prior to invoking your MSI. – Christopher Painter Sep 26 '13 at 11:08
  • Ok, I understand. So if I use another `UpgradeCode` to detect a different product on my conditions, you say I can try to uninstall a different product, isn't it? But... what about if my previous application doesn't use good practices and my ProductVersion is 1.0 and not 1.0.0 or 1.0.0.0? Will it work? – Sonhja Sep 26 '13 at 11:14
  • A few different approaches and considerations. One is that WiX has an attribute called AllowSameVersionUpgrades which gets around a lot of that. You can also schedule RemoveExistingProducts very early on in the sequence if you are having costing problems. Also you can author a fake MajorUpgrade (Fake UpgradeCode guid ) and then use a set property custom action to assign the known ProductCode guid to the action property. This property is how FindRelatedProducts tells RemoveExistingProducts what to remove. One final trick is to change your INSTALLDIR to something slightly different. – Christopher Painter Sep 26 '13 at 11:29