Does anyone know if it is possible to use a single command to install a MSI if it is not already installed, and if it is installed to run a repair/reinstall?

We are using SCCM and would like our users to be able to install an application from Run Advertised Programs, and if they need to repair/reinstall the application e.g. they have accidentally deleted the shortcuts etc. they simply re-run the same advertisement and the command line will accommodate both actions.

I have experimented with running the following command: 'MSIEXEC /i Application.msi /QB REINSTALL=ALL' and this (obviously) works if the application is already installed but does not install the application if it is not installed.

Any assistance is appreciated.
0 Comments   [ + ] Show Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.


Your best option is to use a script, in which you can test for the product's installed state using the WindowsInstaller.Installer object. If it's installed, do a repair. If not, install. The object model is fully documented on MSDN.

BTW, one of the big advantages of using the WI engine is that applications can self-heal, if the installation package is properly constructed.
Answered 04/13/2010 by: VBScab
Red Belt

Please log in to comment
this script will help you, we use it as a pre-req sometimes in sms to determine whether an app is installed or advertised and then uninstall it.
you'll have to change it a bit for your scenario but it's a start

Option Explicit

Const productCode = "{xxxx-xxx-xxxx-xxxxxxx}"
Const productFeat = "Complete"

Const msiProdAdvertised = 1
Const msiProdInstCurrUser = 5

Const msiInstallStateAdvertised = 1
Const msiInstallStateLocal = 3
Const msiInstallAllFeatures = 65535

Dim msiObject : Set msiObject = CreateObject("WindowsInstaller.Installer")
Dim objShell : Set objShell = CreateObject("WScript.Shell")

' Check existing product state
If (msiObject.ProductState(productCode) <> msiProdAdvertised) And (msiObject.ProductState(productCode) <> msiProdInstCurrUser) Then
' Package is neither advertised or installed so exit the script with error code 0 to satify SMS pre-requisite
On Error Resume Next
' If main product feature is either advertised or installed, call uninstall routine via msiexec command line
If (msiObject.FeatureState(productCode, productFeat) = msiInstallStateAdvertised) Or _
(msiObject.FeatureState(productCode, productFeat) = msiInstallStateLocal) Then
objShell.Run("msiexec.exe /x {xxxxx-xxxxx-xxxx-xxxx} /qb!"),1,True
End If
End If
Answered 04/13/2010 by: timmsie
Fourth Degree Brown Belt

Please log in to comment
Answer this question or Comment on this question for clarity