MSI: How to remove all previous versions?

2.7k views Asked by At

Visual Studio 2010 Setup project.

How I can remove all previous versions before installing the new one in that case:

  1. User could install the old version either 'Only for me' or 'For all Users'
  2. The new version can be installed too: 'Only for me' or 'For all Users' Now it installs in parallel.

I can restrict the new version installation to install ME only or FORALLUSERS.

But I need the new version must remove any installed (ME/FORALLUSERS) before installation.

What need to correct in MSI?

2

There are 2 answers

0
Christopher Painter On BEST ANSWER

Windows Installer can only remove previous versions of the same time. Per-Machine removes previous Per-Machine and Per-User removes previous Per-User (same user profile). Mix and match is not possible.

Major Upgrades

Note If an application is installed in the per-user installation context, any major upgrade to the application must also be performed using the per-user context. If an application is installed in the per-machine installation context, any major upgrade to the application must also be performed using the per-machine context. The Windows Installer will not install major upgrades across installation context.

1
herman.smn On

Considering that all versions of a product installation are identified by an UpgradeCode, as a workaround you can try to create a custom action which acts like this:

  1. get all installed products having your UpgradeCode. You can use the MsiEnumRelatedProducts function
  2. launch an uninstall command line like this:

    msiexec.exe /x ProductCode

where the ProductCode is the ProductCode returned by the "MsiEnumRelatedProducts" function.

I haven't tested this implementation, but accordingly to Windows Installer docs it should work.