March 31, 2010

Creating New Custom Actions! Some tips to define Custom Error Messages...

Windows Installer has a long list of predefined error messages and there are many scenarios in which we would need to define Custom error messages for Custom Actions.

Windows Installer suggests the following Tips while creating Custom Error Messages.

  • The error number must be a non-negative integer.
  • The range from 25000 to 30000 is reserved for errors from custom actions. Authors of custom actions may use this range for their custom actions.
However InstallShield users have to be extra carefull to exclude the error codes ranging from 27500 to 27554, which is already being used by recent versions of InstallShield (verified in IS 12, 2009 & 2010) for IIS, Database, COM+, XML etc., related functionality.

March 10, 2010

How to register a .Net assembly into GAC using VBScript CA?

This article focuses on registering .Net assembly into GAC using VBScript Custom Action. We generally use the two approaches detailed here to register .Net Assembly into GAC. In case, if both the approach does not seem to work for your .Net DLL and you observe the following, then VBScript CA detailed below can be used to register the assembly.
  • When building the InstallShield project with .Net COM Interop property set to 'YES' (along with Destination Path to [GlobalAssemblyCache]), if you get the error =>
    Error -6210: An error occurred building COM .NET Interop information for Component [1].
    [1] indicates the part of your installation that is causing this error.
  • When .Net COM Interop property is set to 'NO', building the InstallShield project would succeed but running the installation does not register the .Net assembly into GAC.
Steps to Register .Net Assembly into GAC:
• Add the .Net Assembly to be registered under Support directory.
• Add a VBScript Custom Action (stored in binary table - MSI Type Number : 3078)– RegisterAsmToGAC with the below mentioned code snippet.

Function RegisterAsmToGAC
on error resume next
' Declaration
Const IDABORT=3
Dim szCommand, szCommand1, szCommand2, szCommand3
Dim PropArray, szSupportDir, sProductName,sAssemblyName
' Reading & Parsing the property values in Deferred CA
PropArray = Split(Session.Property("CustomActionData"), ";")
szSupportDir = PropArray(0)
sProductName = PropArray(1)
sAssemblyName = PropArray(2)
'Display Debug Message
'MsgBox szSupportDir, ,sProductName


' Using GACInstaller.exe utility downladed from http://www.codeproject.com/KB/install/GAC_Installer.aspx
szCommand1 = Chr(34) & szSupportDir & "\GacInstaller.exe" & Chr(34)
szCommand2 = " i "
szCommand3 = Chr(34) & szSupportDir & sAssemblyName & Chr(34)
szCommand = szCommand1 & szCommand2 & szCommand3
'MsgBox szCommand, ,sProductName
Set wshShell = WScript.CreateObject ("WScript.Shell")
rc = wshshell.Run(szCommand, 0, True)
if rc <> 0 then
       MsgBox "Error Registering the Assembly", ,sProductName
       wscript.quit
end if

if Err.Number <> 0 then
       MsgBox Err.Number & " - " & Err.Description, ,sProductName
       RegisterAssemblyGAC = IDABORT
End If
End Function

• The RegisterAsmToGAC CA uses 3 MSI Properties (say SUPPORTDIR, ProductName and .Net Assembly to be  registered). By default the MSI properties will not be available to the Custom actions that are in Defered mode.
• To pass parameter to Deferred CA, create a Set Property CA (MSI Type Number: 51) as 'SetRegisterAsmToGAC', set the property name as RegisterAsmToGAC and set the semicolon separated property names to the property value as [SUPPORTDIR];[ProductName];[AssemblyNameToBeRegistered].
• Schedule the SetRegisterAsmToGAC as a Immediate CA after RegisterProduct.
• Schedule the RegisterAssemblyGAC as a Deferred in System Context after SetRegisterAsmToGAC.

February 25, 2010

How to Register a .Net assembly into GAC using WiX?

Ealier we have seen some articles to register a .Net assembly into GAC using either gacutil.exe or RegAsm.exe. In this article we will see the code snippet to register the assembly into GAC using WiX.

<Directory Id="ProgramFilesFolder">
<Directory Id="ProductDirectory" Name="$(var.ProductName)">
      <Directory Id="GAC" Name="GAC">
          <Component Id="MyGACControl" Guid="55857611-A13E-51ED-897B-A78830F68ADC" DiskId="1">
                <!-- Registering assembly in GAC -->
               <File Id="F_MyGACControl" Name="MyGACCtrl.dll" LongName="MyGACControl.dll" Source="$(var.SrcPath)

               \MyGACControl.dll" KeyPath="yes" Assembly=".net"/>
           </Component>
      </Directory>
</Directory>
</Directory>

The highlighted text - Name="GAC" Assembly=".Net", in the above code drives the .Net assembly registration into GAC.


Read the following related articles:
  1. How to register a .Net assembly into GAC in a development environment?
  2. How to Register .Net assembly into GAC using InstallShield 2010?

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.

January 29, 2010

Windows Installer 4.5 Support - InstallShield 2010 SP1

This post focuses on modifying the installer for Windows Installer (MSI) 4.5 Support for Basic MSI and InstallShield MSI Projects.

 Steps:
  • Open the existing InstallShield project in InstallShield 2010 SP1 IDE.
  • Modify the  Schema under General Information - Summary Information Stream to specify the minimum Windows Installer version that is required for your Installation package. Say 405 to support Windows Installer 4.5
  • If the selected minimun Windows Installer version is not available on the target system, then the installer will prompt a message and abort the installation.
  • Also, you can select the Windows Installer 4.5 pre-requisite for the supported operating system from Application Data - Redistributable.
    For Pre-requisite integration, you can choose either of the following 3 options based on various factors
Extract From Setup.exe - The pre-requisites will be bundled with the installer. This is applicable if the Installation Package size is not a constraint / if you want to distribute the installation package as a single compressed file.
Copy From Source Media - The pre-requisite will be stored in a folder 'ISSetupPrerequisites' parallel to the installer.
Download from the Web - At the time of installation, the pre-requisite will be downloaded on the fly from the web and installed. Internet connection is required during installation.
  • If you have not downloaded the pre-requisites already to your installer development machine, right click the Pre-req and click "Dowload the selected Item".
Refer here for dependency errors and solution related to Windows Installer 4.5 Integration.