February 16, 2010

How do you check whether the Patch is Installed already?

This article details on the approach to detect whether the patch is applied or not and prompt the user accordingly. This post applies to Basic MSI & InstallScript MSI Projects and is tested in InstallShield 2008, 2009 & 2010 with SP1. Refer here for the steps to create a Patch using InstallShiled.

• Add a VBScript Custom Action (stored in binary table)– CheckIfPatchInstalled
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Function: CheckIfPatchInstalled
''' Purpose: Checks to see if a patch is installed and sets the value of the property
''' 'PATCHINSTALLED' to "true". This property value is used by the Custom action
''' 'CheckIfPatchInstalledError' to display an error.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function IsPatchInstalled()
            
Dim sProductCode, sProductVersionHF, sProductVersionCurrent
             

             On Error Resume Next
              sProductCode = Session.Property("ProductCode")
             
sProductVersionCurrent = Session.Installer.ProductInfo(sProductCode, "VersionString")
             
sProductVersionBase = Session.Property("ProductVersion")
             
If (sProductVersionCurrent = sProductVersionBase) Then
              
     Session.Property("PATCHINSTALLED") = "true"
             
End If

End Function

• Schedule the CheckIfPatchInstalled as Immediate CA after ISSetupFilesExtract in both Install UI Sequence and Install Exec Sequence with the condition PATCH.
• Add a property PATCHINSTALLED in property manager and leave it empty.
• Add an Error Custom Action as Immediate CA after CheckIfPatchInstalled in both Install UI Sequence and Install Exec Sequence with the condition PATCH AND PATCHINSTALLED.
• Add the appropriate error message say "An existing upgrade is already installed. Please remove it before installing this upgrade." for the Error CA Or Add an entry (Error Number & Message) to the Error Table in the direct editor and use the Error Number in the CA

Create the Patch and apply the patch where the main installer is installed. Running the patch again on the same machine should display the message "An existing upgrade is already installed. Please remove it before installing this upgrade." abort the installation.

No comments:

Post a Comment