问题
We install an application (MSI) using MSIEXEC with the following command line option:
MsiExec.exe /x{code} /qn /liwearucmopvx+ C:\Log\UnInstall.tra
MsiExec.exe /iC:\Source\App.msi /qn TARGETDIR=C:\Install ALLUSERS=1 /liwearucmopvx+ %C:\Log\Install.tra
Most of the time this works, but sometimes the uninstall fails (not sure why yet, looking into the error). Anyways when this happens I get the following error during the re-install:
Another version of this product is already installed. Installation of this version cannot continue. To configure or remove the existing version of this product, use Add/Remove Programs on the Control Panel
Is there a way to bypass this? Meaning to ensure that we always re-install (if it exists we can simply automatically blow it away?)
回答1:
Check out the MSDN Documentation on the Upgrade Table, basically you need to set the msidbUpgradeAttributesVersionMaxInclusive bit.
You don't state what you're using to build your installer, if you're using WiX 3.5 or later you can use MajorUpgrade/@AllowSameVersionUpgrades="yes"
to take care of this for you.
Note that because MSI ignores the fourth product version field, setting this attribute to yes also allows downgrades when the first three product version fields are identical. For example, product version 1.0.0.1 will "upgrade" 1.0.0.2998 because they're seen as the same version (1.0.0). That could reintroduce serious bugs so the safest choice is to change the first three version fields and omit this attribute to get the default of no.
Note that instead of having to remember the package code (a real pain if you're using auto-generated package codes with Continuous Integration) the following VBScript will remove the package by name by searching the list of installed products and finding the package code itself.
Option Explicit
Dim productName, productCode, installer
productName = "My Application"
Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
For Each productCode In installer.Products
If InStr(1, LCase(installer.ProductInfo(productCode, "ProductName")), LCase(productName)) Then Exit For
Next
If Not IsEmpty(productCode) Then
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("msiexec /x " & productCode & " /qb /l*v ""%temp%\UninstallApp.log"" ")
End If
回答2:
If the uninstallation fails the product will still be registered on the system - depending on where the failure occurs the uninstallation will rollback, leaving the product still installed.
If you attempt to reinstall a product with the same product code but different version on top of an existing installation MSI will complain, rightly, that the product is still installed. If you want to achieve upgrade behaviour then you need to change the product code and write entries into the upgrade table so that MSI can discriminate between the old and new products and use the RemoveExistingProducts action to remove the old product before or after the newer version is laid down.
If you want to understand why the uninstallation failed, you need to look at the logs, typically look for 'return value 3' which is the signature of a failed installation action.
回答3:
The question is quite older, but the existing answers are missing the essence of problem and solution while useful for other scenarios:
If the uninstall fails, you have a serious problem, and there is no better way than analyzing this- otherwise you could get in more trouble later.
At least, I would write a small script/program, which uses the return value of the uninstall or, even more powerful, tests, if the MSI is still installed- BEFORE you try to install the new MSI.
I would give more information how to do this, if there is interest in this, but there is already information on SO in other questions.Some other answers recommand, that you should use Major Upgrades (every new build can/should be a correct Major Upgrade in this scenario, at least as a recommendation). This is a good recommendation, but does not help, if uninstalls are failing "sometimes". Moreover it is important to state, that most often, the error you mention, shows that you are not using Major Upgrades already. If you have really a problem with uninstalls, then a Major Upgrade could increase problems, because dependent on the configuration, it can install the product a second-time MSI-wise and you have two MSI references on this, what is still one product for you. More details would lead too far. Just remember, an (always) working uninstall or at least a test for this has to be assured before further update steps.
The script from saschabeaumont is really short and nice. What it is doing, is to assure, that you are really using the correct ProductCode. The main need is, because it has to change every time, you produce a Major Upgrade... In your case: This solves only ONE scenario, why your uninstall could have failed...
来源:https://stackoverflow.com/questions/3970862/msi-install-fails-because-another-version-of-this-product-is-already-installed