Bhalchandra K
Bhalchandra K

Reputation: 2681

custom action after installation failed

How to sequence a custom action to execute only when installation is interrupted or completed with error?

Is there any windows installer property which returns current installation status (failed/succeed)?

Upvotes: 3

Views: 3599

Answers (2)

Yan Sklyarenko
Yan Sklyarenko

Reputation: 32270

The OnExit attribute of the <Custom> element is what you're looking for. It is mutually exclusive with Before, After, and Sequence attributes and can have the following values: success, cancel, error, suspend.

UPDATE: basically, this is what I mean:

1) Define a custom action which will do the work you'd like it to do (gather some failure data). Note that you'll have to define N custom actions pointing to the same target because the CustomAction MSI table expects Id as a primary key (let's assume it's DLL CA):

<CustomAction Id="LogFailureOnCancel" BinaryKey="CustomActions" DllEntry="LogFailure" ... />
<CustomAction Id="LogFailureOnError" BinaryKey="CustomActions" DllEntry="LogFailure" ... />

NOTE: both definitions point to the same real action (DllEntry attribute).

2) Schedule these custom actions appropriately:

 <Custom Action="LogFailureOnCancel" OnExit="cancel" />
 <Custom Action="LogFailureOnError" OnExit="error" />

Upvotes: 7

Michael Urman
Michael Urman

Reputation: 15905

To the extent that Windows Installer allows it, this is only possible during custom actions scheduled for rollback. However rollback only applies to the deferred script, so it's only available for actions scheduled between InstallInitialize and InstallFinalize. If an immediate-mode action outside this scheduling window causes the installation to abort, rollback does not apply.

Assuming you're using a C++ or InstallScript action, you can find out if rollback is enabled, and if you're in rollback, with calls to MsiGetMode - using MSIRUNMODE_ROLLBACKENABLED or MSIRUNMODE_ROLLBACK respectively.

Upvotes: 0

Related Questions