Easy MSI - A basic guide to Windows Installer

Click here to edit subtitle

Chapter 4 - Sequences and Actions


Download Solution 4.1 - 4.8

Download Solution 4.9 - 4.10

Download Solution 4.11 - 4.14

Download Solution 4.15


Excercise 4.1: The PauseCA


In this exercise you will use a simple VBScript Custom Action to set a break during the installation.


Open your blastermaster.msi with InstEd and add the following new record to the CustomAction table:

Column
 value
 Action
 PauseCA
 Type
 0x0026
 Source
 <null>
 Target
 MsgBox "Pause"
 ExtendedType
 <null>

Next add the following record to the InstallExecuteSequence table.

Column
 value
 Action
 PauseCA
 Condition
 <null>
 Sequence
 6500
Finally add the following record to the ActionText table.
column
 value
 Action
 PauseCA
 Description
 Displaying Pause Message Box
 Template
 <null>

Excercise 4.2: The PauseCA Type 54


In this exercise you will modify the PauseCA Custom Action to a Type 54 Custom Action.


Therefore modify the record in the CustomAction table as follows:

column
 Value
  Action
 PauseCA
 Type
 0x0036
 Source
 Prop_SrcCode_DemoCA
 Target
 <null>
 ExtendedType
 <null>

Then add the following record to the Property table.

Column
 value
 Property
 Prop_SrcCode_DemoCA
 Value
 MsgBox "Pause"

Excercise 4.3: A VBScript Custom Action for installing a service


In this exercise you will add a new VBScript Custom Action for installing a Windows Service.


However first remove the PauseCA CustomAction from the InstallExecuteSequence table.


Once this is done add the following new record to the Property table:

column
 Value
 Property
 Prop_BMServicePath
 Value
 C:\BlasterMaster\

Next add the following record to the CustomAction table.

column
 Value
 Action
 CreateBMServiceCA
 Type
 0x0006
 Source
 BMService.vbs
 Target
 CreateService
 ExtendedType
 <null>

Next add the following record to the ActionText table.

Column
 Value
 Action
 CreateBMServiceCA
 Description
 Creating Windows Service
 Template
 <null>

Then add the following record to the InstallExecuteSequence table.

column
 Value
 Action
 CreateBMServiceCA
 Condition
 &Feature_BlasterMasterService=3
 Sequence
 7000

Next add the following record to the Property table.

Column
 Value
 Property
 MSIUSEREALADMINDETECTION
 Value
  1

Finally add the following record to the LaunchCondition table.

column
 Value
 Condition
  Privileged 
 Description
  This package requires admin rights to run.

The VBScript code for installing the service requires administrative privileges. Therefore when you want to install the blastermaster.msi you need to open a CMD with administrative privileges and execute msiexec.exe /i blastermaster.msi.


After uninstalling the package again, delete the service again manually calling sc delete BMService in a CMD running with administrative privileges.


Excercise 4.4: Executable Custom Actions


In this exercise you will add two Executable Custom Actions to your blastermaster.msi package.


First we add a custom action for uninstalling the Windows Service you installed before. Thus, add the following new record to the CustomAction table.
column
 Value
 Action
 UninstallBMServiceCA
 Type
 0x0032
 Source
 ScExePath
 Target
 delete BMService
 ExtendedType
 <null>

Next add the following record to the Property table.

Column
 Value
 Property
 ScExePath
 Value
 C:\Windows\system32\sc.exe

Then schedule this Custom Action in the InstallExecuteSequence table.

column
 value
 Action
 UninstallBMServiceCA
 Condition
 &Feature_BlasterMasterService=2
 Sequence
 5840

Now we add another executable custom action to launch the BlasterMaster.exe once the installation has finished. 

Thus, add the following new record to the CustomAction table.

column
 Value
Action
 RunBlasterMasterCA
 Type
 0x0012
 Source
 File_BlasterMaster.exe
 Target
 <null>
 ExtendedType
 <null>

Finally schedule this action in the InstallExecuteSequence table.

column
 value
 Action
 RunBlasterMasterCA
 Condition
 NOT Installed
 Sequence
 8000

Excercise 4.5: DLL Custom Action


In this exercise you will add a DLL Custom Actions to your blastermaster.msi package.


First stream the file MyFirstDLLCA.CA.dll into the Binary table.


Then add the following new record to the CustomAction table.

column
 Value
 Action
 MyFirstDLLCA
 Type
 0x0001
 Source
 MyFirstDLLCA.CA.dll
 Target
 MyDLLCAEntryPoint
 ExtendedType
 <null>

Then schedule the Custom Action in the InstallExecuteSequence table.

column
 Value
 Action
 MyFirstDLLCA
 Condition
 <null>
 Sequence
 5810

Finally install the MSI package from an (administrative) cmd by calling

msiexec.exe /i blastermaster.msi /Lv mylog.txt


Excercise 4.6: Set Property Custom Action


In this exercise you will add a Set Property Custom Actions to your blastermaster.msi package.


First add the following record to the CustomAction table.

column
 Value
 Action
 SetPropertyProp_BMServicePath
 Type
 0x0033
 Source
 Prop_BMServicePath
 Target
 [TARGETDIR]
 ExtendedType
 <null>

Then add the following record to the InstallExecuteSequence table.

column
 Value
 Action
  SetPropertyProp_BMServicePath
 Condition
 <null>
 Sequence
 1020

Excercise 4.7: Set Directory Custom Action


In this exercise you will add a Set Directory Custom Actions to your blastermaster.msi package.


First, add the following record to the CustomAction table.

Column
 Value
 Action
 SetDirectoryTARGETDIR
 Type
 0x0023
 Source
 TARGETDIR
 Target
 [%ProgramFiles]\[Manufacturer]\[ProductName]
 ExtendedType
 <null>

Then add the following record to the InstallExecuteSequence table.

column
 Value
Action
   SetDirectoryTARGETDIR
 Condition
 <null>
 Sequence
 1010

Excercise 4.8: Error Custom Action


In this exercise you will add an Error Custom Actions to your blastermaster.msi package.


First add the following record to the CustomAction table.

column
 value
 Action
 MissingNETFRAMEWORK35ErrorCA
 Type
 0x0013
 Source
 <null>
 Target
 This installation requires .NET Framework 3.5.
 ExtendedType
 <null>

Then add the following record to the InstallUISequence table.

column
 value
 Action
 MissingNETFRAMEWORK35ErrorCA
 Condition
 NETFRAMEWORK35
 Sequence
 110

Finally add the following record to the InstallExecuteSequence table.

column
 Value
 Action
 MissingNETFRAMEWORK35ErrorCA
 Condition
 NETFRAMEWORK35
 Sequence
 110

Excercise 4.9: Deferred Custom Action


In this exercise you will add a Deferred Custom Actions to your blastermaster.msi package.


First add the following record to the CustomAction table.

column
 Value
 Action
 MyDeferredVBScriptCA
 Type
 0x0426
 Source
  <null>
 Target
 MsgBox Property("CustomActionData")
 ExtendedType
  <null>

Then schedule the Custom Action in the InstallExecuteSequence table.

column
 Value
 Action
 MyDeferredVBScriptCA
 Condition
 <null>
 Sequence
 6500

Next add the following record to the Property table.

column
 Value
 Property
 MyDeferredVBScriptCA
 Value
  

Then add the following record to the CustomAction table.

Column
 Value
 Action
 MyDeferredVBScriptCA.SetProperty
 Type
 0x0033
 Source
 MyDeferredVBScriptCA
 Target
 [TARGETDIR];[ProductName]
 ExtendedType
 <null>

Finally schedule this Custom Action also in the InstallExecuteSequence table.

Column
 Value
 Action
 MyDeferredVBScriptCA.SetProperty
 Condition
 <null>
 Sequence
 6450

Excercise 4.10: Rollback Custom Action


In this exercise you will add a Rollback Custom Actions to your blastermaster.msi package.


Thus, add the following record to the CustomAction table.

column
 Value
 Action
 MyRollbackCA
 Type
 0x0526
 Source
 <null>
 Target
 MsgBox "Rollback"
 ExtendedType
 <null>

Then add the following record to the InstallExecuteSequence table.

Column
 Value
 Action
 MyRollbackCA
 Condition
 <null>
 Sequence
 6449

Next modify the Deferred Custom Action from above in the CustomAction table to provocate an error:

Column
 Value
 Action
 MyDeferredVBScriptCA
 Type
 0x0426
 Source
 <null>
 Target
 provoke_error
 ExtendedType
 <null>

Excercise 4.11: Commit Custom Action


In this exercise you will add a Commit Custom Actions to your blastermaster.msi package.


But first remove the following records from the CustomAction table: MyDeferredVBScriptCA, MyDeferredVBScriptCA.SetProperty


Then add the following record to the CustomAction table.

column
 Value
 Action
 MyCommitCA
 Type
 0x0626
 Source
 <null>
 Target
 MsgBox "Commit"
 ExtendedType
 <null>

Then add the following record to the InstallExecuteSequence table.

Column
 value
 Action
 MyCommitCA
 Condition
 <null>
 Sequence
 6448

Excercise 4.12: Deferred Execution in System Context


In this exercise you will make your deferred Custom Actions that creates the Service run in System Context.


First modify the file BMService.vbs as described in the book and stream it again into the Binary table.


Then modify the CreateBMServiceCA record in the CustomAction table as follows:

column
 Value
 Action
 CreateBMServiceCA
 Type
 0x0c06
 Source
 BMService.vbs
 Target
 CreateService
 ExtendedType
 <null>

Then change the position for the CreateBMServiceCA record in the InstallExecuteSequence table so that it runs before InstallFinalize.

column
 value
 Action
 CreateBMServiceCA
 Condition
  &Feature_BlasterMasterService=3
 Sequence
 6550

Next add the following record to the CustomAction table.

column
 Value
 Action
 CreateBMServiceCA.SetProperty
 Type
 0x0033
 Source
 CreateBMServiceCA
 Target
 [Prop_BMServicePath]
 ExtendedType
 <null>

Then schedule the Custom Action in the InstallExecuteSequence table.

Column
 value
 Action
 CreateBMServiceCA.SetProperty
 Condition
 &Feature_BlasterMasterService=3
 Sequence
 5849

Finally remove the "Privileged" record from the LaunchCondition table.


You can now install the package by just double-clicking it. You don't need to run msiexec.exe in an administrative CMD anymore. 

However uninstallation will fail as long as you don't make the service uninstallation action also deferred / no impersonation. 

Thus, when you uninstall the package you have to call msiexec.exe /x blastermaster.msi in an administrative CMD.


Excercise 4.13: Return Processing of Custom Actions


In this exercise you will modify the Custom Action from the exercise above so that the installation continues also in the case that the Custom Action fails.


Therefore modify the CreateBMServiceCA in the CustomAction table as follows:
Column
 Value
 Action
 CreateBMServiceCA
 Type
 0x0c46
 Source
 BMService.vbs
 Target
 CreateService
 ExtendedType
 <null>

Excercise 4.14: Asynchronous Custom Actions


In this exercise you will modify the Custom Action from the exercise above so that it runs asynchronously.


Therefore modify the CreateBMServiceCA in the CustomAction table as follows:

Column
 Value
 Action
 RunBlasterMasterCA
 Type
 0x0092
 Source
 File_BlasterMaster.exe
 Target
  <null>
 ExtendedType
 <null>

Excercise 4.15: Clean up


Most of the examples were only for learning purposes and are not really required for installing Blaster Master. Thus, it is now time to clean up your package from these artificial examples. Hence, remove the following records from the CustomAction table: 

PauseCA, MyFirstDLLCA, MyRollbackCA, MyCommitCA, MissingNETFRAMEWORK35ErrorCA, CreateBMServiceCA, CreateBMServiceCA.SetProperty, 

SetPropertyProp_BMServicePath, UninstallBMServiceCA


Next remove the following records from the Property table:

Prop_BMServicePath, MyDeferredVBScriptCA, Prop_SrcCode_DemoCA, ScExePath