Thursday, October 6, 2011

Add CustomAction to a MSI package

We used CustomActions to implement easy and quick (possibly dirty) changes before finishing the software installation.

Start editing the MSI file (e.g. using Orca)
It's best practice to not directly edit an MSI, but using a transform (MST) instead.

Open the table CustomAction
Add a new row, defining the following values:

Action:  <unique name>
Type:     3110
Type 38     = VBScript text stored in this sequence table.
Type 3072 = Queues for execution at scheduled point within script. Executes with no user impersonation. Runs in system context.
3072 + 38 = 3110
http://msdn.microsoft.com/en-us/library/aa372048(VS.85).aspx
Source: <empty>
Target:   <write a VBScript>

Example 1: Copying a file
Set FL = CreateObject("Scripting.FileSystemObject"):FL.CopyFile "\\server\share$\file.dat", "C:\Program Files\ExistingFolder\file.dat", TRUE

Example 2: Change registry settings
Set S = CreateObject("WScript.Shell"):X="HKLM\Software\JavaSoft\Java Update\Policy\":Y="REG_DWORD":S.RegWrite x&"EnableJavaUpdate",0,Y:S.RegWrite x&"EnableAutoUpdateCheck",0,Y:S.RegWrite x&"NotifyDownload",0,Y:S.RegWrite x&"NotifyInstall",0,Y:S.RegWrite x&"Frequency",0,Y:S.RegWrite x&"UpdateSchedule",0,Y

Change to the table InstallExecuteSequence
Add a new row, using the following values:

Action:          <same name as used in CustomAction>
Condition:    NOT Installed
Sequence:   <number before InstallFinalize>
To figure out a working sequence number, sort the rows by sequence.
Search for the "InstallFinalize" sequence number and notice this value.
Decrement the noticed value by 1 and check if this value is already used.
If not, you've found your sequence number.
If yes, renumber the values, until you got a free sequence number right before "InstallFinalize".

No comments:

Post a Comment