Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

installation - MSI Install Fails because "Another version of this product is already installed"

We install an application (MSI) using MSIEXEC with the following command line option:

MsiExec.exe /x{code} /qn /liwearucmopvx+ C:LogUnInstall.tra
MsiExec.exe /iC:SourceApp.msi /qn TARGETDIR=C:Install ALLUSERS=1 /liwearucmopvx+ %C:LogInstall.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?)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...