Thursday 21 July 2011

Service Packs and How to Package Them

Here are the 3 ways to wrap exe
1)By using Custom Action: Execute Program from Installed File
For this method you need to first add the downloaded SP3 exe to some location in your WSI. For example you can copy it to C:\Windows\Temp
This is shown in the below illustration:

As you can see the .exe is added to the Temp Folder. Now our aim is to install this patch. For this you need to go to MSI Script section -> All Custom Actions
On Left hand side double click on the Action: Execute program from Installed Files.
A Window will open in which you can fill in the details:
First on the detail tab:
Custom Action Name: ( As per your company standards ) Example: Install_SP3
Command Line Arguments: This depends on your requirements, but to keep it silent installation and preventing it to restart the machine, I have given the command line arguments as: /quiet /passive /norestart /o
Executable File: To add the executable file click on the Browse button. A Window will open with the executable file in the Windows Temp folder.
Select the file and click OK.
Next, Go to Location Tab and uncheck the No Sequence check box.
In the Sequence select Normal Execute Immediate / Deferred
Place the Custom Action just above InstallFinalize.
Give the condition in the below box as: NOT Installed AND NOT PATCH
The condition mentioned above is Case sensitive.
We are using this Condition so that this Custom Action works only during installation and not at repair. There is no need to run it at repair because this is a Service Pack and not an ordinary MSI.
Now in the properties tab, select In Script Option as Deferred Execution, System Context and Processing as Synchronous, Ignore exit code. This is shown in the attached image:
If you want you can fill in the Description tab, else it is not required.
The reason for keeping it in Synchronous is that it will wait for the patch to execute and then will finish the installation of the MSI.
There is no need to worry about deleting the exe file added in Windows Temp folder after the installation of the package. Also there is no need to worry if it is deleted as there will be no self heal because there is no advertised shortcut in the package, nor is the file required after the package is installed.
Now you can compile your MSI after making the custom changes in the WSI as per your company standards.
This is one way of wrapping the exe.
2)By using Custom Action: Execute Program from Installation
For using this method, there is no need to add the downloaded Service Pack file to the file section in your package. However you will need to put in some dummy file or registry to create at least one component in your package.
We need to follow the following steps:
First, you need to go to MSI Script Section. On the left column double click on the Action: Execute Program from Installation. A window will open where you can fill in the details.
Details tab:
Custom Action Name: INSTALL_SP3
Command Line Arguments: /quiet /passive /norestart /o
Executable File: Click on Browse and select the file from your machine as shown in the below figure.
Location Tab:
In Location Tab, uncheck the No Sequence button and in Sequence select Normal Execute Immediate / Deferred.
Place the Custom Action just before InstallFinalize as shown in the below figure.
Give the Condition as NOT Installed AND NOT PATCH
In the Properties Tab, select In Script Option as Deferred Execution, System Context and Processing as Synchronous, Ignore exit code as shown in the below figure:

After adding this Custom Action, if you go to the binary table then you will see that the SP3 exe is added to the binary table.
Now you can do all other customizations in your package according to your company standards and compile the package.
3)By using VB Script: You can also use VB Script to install the patch
For this method you need to first add the downloaded SP3 exe to some location in your WSI. For example you can copy it to C:\Windows\Temp
This is shown in the below image:
As you can see the .exe is added to the Temp Folder. Now our aim is to install this patch. For this you need to go to MSI Script section -> All Custom Actions
On Left hand side double click on the Action: Call VBScript from Embedded code.
In the Details section you have to add your VBScript which will install your service pack. You can use the following VBScript in your package:
Set objShell = CreateObject("WScript.Shell")
Set objFso = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

If objFso.FileExists("%WINDOWS%\Temp\XPSP2_en.exe") Then
        strInstall = "%WINDOWS%\Temp \XPSP2_en.exe /quiet /passive /norestart /o "
Return = ObjShell.Run(strInstall, 0, True)
End If

You should use environment variables instead of hard coded paths as per the best practices.
Location Tab:
In Location Tab, uncheck the No Sequence button and in Sequence select Normal Execute Immediate / Deferred.
Place the Custom Action just before InstallFinalize as shown in the below figure.
Give the Condition as NOT Installed AND NOT PATCH.
In the Properties Tab, select In Script Option as Deferred Execution, System Context and Processing as Synchronous, Ignore exit code as shown in the below figure:
Now you can do all other customizations in your package according to your company standards and compile the package.
By using VBScript in embedded code, you get an ICE error. If you do not want that ICE Error, then you should use Execute VBScript from Installation Custom Action and embed that VBScript in Binary table.

1 comment: