Custom Search

Custom Actions

Custom Actions

Custom Actions are used when the MSI developer needs a functionality out of the scope of Windows Installer engine's Standard Actions are not enough to accomplish a given installation task.

Removing a file / folder during installation / Uninstallation can be done using the removefiletable, but there are certain limitations too. Dynamically created files / Folders like log folders in the INSTALLDIR / Log files, Directory used by some services to launch, windows installer cannot delete these folders as long as the service is in use and the service is stopped and deleted from the machine.

Custom Action Types and Sequences

WiseScript Custom action

You can use VB Script, Wise Script, DLL ..... for creating Custom Actions.

If you want to run a script During installation and after the product is installed.

Run in : Execute deffered
Condition : If Not Installed

If you want to run a script during removal of the product

Run in : Execute deffered
Condition : If Remove~="ALL"

Using the Custom Action Properties Tab
The Properties tab appears on the details dialog for most custom actions. However, sometimes options are disabled or display different choices based on what kind of custom action you added and where you added it. In this dialog, you set options that determine when and how the custom action is run.

In-Script Options
This determines when the custom action is executed. When Windows Installer runs the installation, it first reads the action sequences and creates its own internal installation script to follow, then later it executes that script. You can have the custom action executed immediately when Windows Installer first encounters it, or later during execution of the internal script. See Custom Action In-Script Execution Options in the Windows Installer SDK Help.

Note : The In-Script Options drop-down list is disabled if this custom action is located in the User Interface or Execute Immediate sequences because both these sequences already run in immediate execution mode, making this drop-down list redundant. It is disabled for Set Property and Set Directory because they must be run in immediate execution mode in order to work.

Immediate Execution
If you place an action in the User Interface or Execute Immediate sequence, this is set to Immediate Execution and is disabled, because those two sequences always run in immediate execution. This action will be executed during Windows Installer's first pass through the installation database, before the internal script is generated and executed. Actions in immediate execution mode can change properties; actions in any type of deferred mode cannot. Actions in immediate execution mode always run under User Context, which means that they run with the same privilege level as the currently logged-in user. If the custom action needs to be run under a higher privilege level, place it in the Execute Deferred sequence and set this field to Deferred Execution - System Context.

Note : The following four options all apply to deferred custom actions, and are available only if the custom action is placed in the Execute Deferred sequence. Otherwise the drop-down list is disabled.

Deferred Execution - User Context
Select this if the action should be executed later during installation, during the time when all other system changes are performed by Windows Installer. This runs under user context, so if the current user doesn't have elevated privileges, and the action needs elevated privileges to succeed, it might fail. Use this option if the custom action depends on a file that is installed with the installation. Custom actions that change the system directly should be run in Deferred Execution. Deferred custom actions cannot change properties in the Property table. See Deferred Execution Custom Actions in the Windows Installer SDK Help.

Rollback only
Select this if the action should be executed later, during installation of the rollback script, which is invoked if the end user cancels the installation or if the installation is unsuccessful. Use rollback actions to undo previous custom actions that made changes to the system. Rollback actions run in deferred execution mode and cannot run asynchronously. See Rollback Custom Actions in the Windows Installer SDK Help.

Commit only
Select this if the action should be executed later, during installation of the commit script, which is invoked upon successful completion of the installation script. Commit actions run in deferred execution mode. See Commit Custom Actions in the Windows Installer SDK Help. t Deferred Execution - System Context If execution of the custom action requires elevated privileges, set this option. You must also set AlwaysInstallElevated keys in the registry. See AlwaysInstallElevated in the Windows Installer SDK Help. This makes the custom action run as though it were logged in as a system account, similar to the way services can log in as a system account. Note User context and system context are relevant only on locked-down Windows NT, Windows 2000, and Windows XP computers. Actions run in system context are run with elevated privileges by the Windows Installer service. Actions run in user context are run with the current user's privileges. Processing The main installation thread can control the custom action thread in different ways. Options in this drop-down list determine how the custom action thread is controlled. See Custom Action Return Processing Options and Synchronous and Asynchronous Custom Actions in the Windows Installer SDK Help. The Processing options are not available if the custom action type is Set Property or Set Directory and are limited to synchronous for Install MSI custom actions.

Synchronous
Run the custom action synchronously to the main installation thread. Windows Installer waits for the custom action to complete before continuing the main installation. The exit code of the custom action must be 0 to indicate success. Use this method for Windows Installer to wait for the success of the action before continuing.

Synchronous, Ignore exit code
Run the custom action synchronously to the main installation thread. Windows Installer waits for the custom action to complete before continuing the main installation. Use this option if success of the action is unnecessary to continue with the installation. The exit code of the custom action is ignored.

Asynch, Wait at end of sequence
Run the custom action asynchronously to the main installation thread. Windows Installer runs the custom action simultaneously with the main installation. At the end of the script, Windows Installer waits for the exit code from the custom action before continuing. Use this if the installation is not dependent on completion of this action, but you want to check the exit code. This option is not available for Install MSI custom actions or if you selected Rollback Only in the In-Script Options list above.

Asynch, No wait
Run the custom action asynchronously to the main installation thread. This means that Windows Installer runs the custom action simultaneously with the main installation. Windows Installer does not wait for completion of the custom action and does not check the exit code. This option is not supported for Install MSI custom actions. This option is not supported for Install MSI custom actions or if you selected Rollback Only in the In-Script Options list above.

Scheduling Options
If you add the custom action to both the UI Sequence and the Execute Sequence, but you want to limit the number of times it actually runs, select an option here.

Always Execute
Select this to have the action execute in all sequences that you added it to.

Run first time
Select this to have the custom action execute only the first time Windows Installer encounters it.

Run once per process
Select this option to prevent the custom action from running twice if the custom action modifies property or database data. Use for custom actions in either Execute sequence that should not run if the installation is running in silent mode.

Run only if UI sequence was run
Select this option if the custom action should run only if either Execute sequence is run following User Interface sequence.

When to use deffered and when to use Immediate
Deferred custom actions should be used when the custom action must make a change to the system or callanother system service. Additionally, only deferred custom actions can run in an elevated context. If yourcustom action requires elevated privileges in order to run, your custom action needs to be marked asdeferred. Note: Custom actions marked to run in the system context (msidbCustomActionTypeInScript +msidbCustomActionTypeNoImpersonate) will only run in the system context if the installation itself iselevated.


Additionally, when making a change to the system by means of a custom action, you should also include a rollback custom action that can undo the change.

Advanced Custom Actions
http://www.appdeploy.com/articles/msicustomactions/