Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to uninstall previous version as part of msi install?

I have a product that's packaged as an MSI. When my customers install a new version of my product over the top of an existing version it's not working nicely because of a custom VBS action, as explained below. My question is: how I can change my MSI so that installing over the top will always do a full uninstall of any existing version beforehand?

The detail is:

I have a product with a variety of versions deployed at various different companies. About once a year each of my customers would receive a new version of my product and deploy to their company's workstations. The people responsible for deployment would prefer they can install the new version over the top of the old version, instead of having to include an uninstall step in their install package.

The msi install creates and writes some files to [CommonApplicationData]\MyApp folder. During execution the application creates more files in [CommonApplicationData]\MyApp folder. During uninstall I need to delete all these files. Since they're not installed by the msi they aren't automatically uninstalled, so I created a vbs script that deletes that folder and anything else in it. I put a command to execute that vbs in ExecuteDeferred:

...
RemoveFiles
RemoveFolders
CreateFolders
MoveFiles
InstallFiles
PatchFiles
If REMOVE="ALL" Then
    REM line below is my custom script
    call VBScript From Installation (MyApp_UninstallCleanup)  
End
DuplicateFiles
BindImage
CreateShortcuts
...

So far so good and it works fine when installing & uninstalling. However, if I install a new version of my product over the top of an existing version it appears things happen in this order: a) install new version, creating various files in [CommonApplicationData]\MyApp folder, and in [Program Files]\MyApp..., overwriting files of old version b) run my vbs, deleting the [CommonApplicationData]\MyApp folder

I do have the GUIDs for the old versions listed in the Upgrade table in my new MSI, and apart from this custom script the upgrade process seems to work ok.

The product itself is pretty small so it would be fine if the installer always removed previous versions entirely before installing the new version. There are no user settings on the workstation that need to be retained and the file sizes aren't large. Hence for simplicity I want the previous versions to be uninstalled rather than updated with only the bits that have changed.

Is there a way I can change my new MSI so that it will uninstall previous versions first?

Notably, I have many companies who have the existing version of the MSI installed that contains the custom vbs. So the solution really needs to be one that can cope with the existing installed msi.

I've used Wise Installation Express 7.0 to create the MSI.

thanks!!

(cross-posted here)

like image 543
Rory Avatar asked Jul 04 '12 11:07

Rory


People also ask

How do I uninstall old MSI?

Uninstalling an MSI from the command line using the msiexec.exe. If you have access to the original MSI, then you can use the msiexec /x <path to the MSI file> command to uninstall your application. Windows Installer technology uses msiexec.exe for both the installation and uninstallation of MSI packages.

How do I customize an MSI installer?

Similar to Orca, to edit your MSI package, right-click it and select “Open with Advanced Installer”. Once the MSI database has loaded in Advanced Installer, you will notice a left menu pane where you will find all the options you need to directly edit your MSI.

Where are MSI installers stored?

The Windows Installer cache is located in the folder: %windir%\installer. When a product is installed by using Windows Installer, a stripped version of the original . msi file is stored in the Windows Installer cache.


2 Answers

Schedule RemoveExistingProducts action before InstallInitialize action:

In this case, the installer removes the old applications entirely before installing the new applications. This is an inefficient placement for the action because all reused files have to be recopied.

like image 186
Alexey Ivanov Avatar answered Sep 18 '22 04:09

Alexey Ivanov


Answer from EdT on Symantec forums

If you have used the standard Wise template for your installs, then the RemoveExistingProducts action is sequenced at the end of the InstallExecute sequence. Although technically this is the most "efficient" placement, unless you have very carefully run UpgradeSync when creating your new package to upgrade the old, the end result is usually one of missing files or other aberrations.

The fix is to re-requence the RemoveExistingProducts action so that it runs between InstallValidate and InstallInitialize. That ensures that the old app is removed entirely before the new version is installed.

Look up "RemoveExistingProducts" in the help file MSI.CHM for a more detailed explanation of the options for positioning this action.

like image 36
Rory Avatar answered Sep 18 '22 04:09

Rory