canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

How to cancel installation properly?

Hello everyone.

I tried to cancel an installation in two ways:

1) Return value 2 of an attached custom action (using the default config, that is run immediate, etc. pp.):
Return value gets ignored, installer reports success. I found suggestions that only the return value of inline custom actions are being evaluated.

2) Set (new) property in attached custom action, evaluating existence of the property in the condition of an ErrorMessage custom action:
The error messages shows up, user presses "OK", installer shows page informing user about problem and claiming that no files were copied to the computer.
Looking at the installation directory all files are there however.


What would be the correct way to cancel the installation in a way that cleanup is being performed properly?



With best regards

Clemens Anhuth
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: How to cancel installation properly?

Hi,
What would be the correct way to cancel the installation in a way that cleanup is being performed properly?
In order to cancel the installation and perform a rollback, a custom action must:
- be scheduled between the "InstallInitialize" and "InstallFinalize" standard actions as deferred
- return one of the following values:

Code: Select all

1626 - A function could not be executed.
1602 - A user canceled installation.
1603 - A fatal error.
Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: How to cancel installation properly?

Hello Cosmin,

thank you for the information.



Bye bye

clemens
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: How to cancel installation properly?

Hello Cosmin,

I am sorry, but I still seem to be confused about when Windows Installer does what.

I need to execute a custom action after the files have been copied to the target directory. Should something fail in that custom action I want to rollback the installation, via a deferred custom action.

Should the following work?

- Execute my custom action immediately after action X
- Set a property in case of an error in my immediate custom action
- Execute a deferred custom action after action Y to perform the rollback in case the "error property" is set

If it should work, after which actions should I execute my immediate and my deferred custom actions?

I added popup messages after each action and it seems that copying all files to the target directory is being done in the InstallFinalize action, is that correct?

If so, that means I cannot use the "rollback" mechanism of the installer (the way you described it), but instead will have to remove the installed files myself, in a custom action executing after InstallFinalize?



With best regards

Clemens Anhuth
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: How to cancel installation properly?

Hi Clemens,

The files are copied in the installation folder during the "InstallExecuteSequence" -> "InstallFiles" standard action. Therefore, if you want to run a custom action after the files are installed, you can scheduled it after "InstallFiles". Please note that all standard actions run as deferred, therefore your custom action should also be deferred.

Since the "InstallFiles" standard action and your custom action run as deferred, I'm afraid that you cannot set installer properties in your custom action. However, you can make sure that a custom action is executed during a rollback by selecting the "Rollback" execution option for it (the condition of the custom action should be "NOT Installed").

Please note that a rollback custom action should be scheduled before the action it rolls back. Therefore, you can have this sequence:

Code: Select all

InstallExecute Sequence
    InstallFiles -> runs as deferred
    RollbackCustomAction -> has the "Rollback" option set
    CustomAction -> has the "Deferred" option set
The installation process runs two times:
- the first time it adds into an execution script all standard actions and custom actions which have a true condition; this is when "Immediate" custom actions are executed
- the second time it executes all standard actions and custom actions in the script; this is when Deferred, Rollback and Commit custom actions run

Therefore, if your custom action depends on a standard action it should be executed as Deferred.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: How to cancel installation properly?

Hello Cosmin,

thank you for this information.

The next challenge then (it seems like there is a never ending supply of surprise in Windows Installer) was to tell my deferred action what the installation path (APPDIR) is so that it can do its job.

Since accessing existing properties doesn't work in deferred actions I had to create a custom action that sets a property of the name of the function to be called in my deferred action to the desired value.

Then, in my custom action, I don't retrieve that value from a property of the name of the function (nooo, that would be obvious), instead I have to retrieve it from a property called "CustomActionData".

Microsoft explains this bizarre mechanism here: Obtaining Context Information for Deferred Execution Custom Actions

Cosmin, for maintenance sake, is there another, simpler, more obvious way to make that one APPDIR value available to my deferred custom action?

If not, that's just as well, as long as the problem is solved, but the constant stream of suprises of this kind really keeps my adrenaline level at an unhealthy level. :-[



With best regards

Clemens Anhuth
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: How to cancel installation properly?

Hi Clemens,

Please note that deferred custom actions can use the Action Data field. Basically, you can add "[APPDIR]" to this field and retrieve its value from CustomActionData inside your custom action (the Action Data field sets the CustomActionData property).

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
canhuth
Posts: 241
Joined: Thu Jun 19, 2008 9:03 am

Re: How to cancel installation properly?

Cosmin,

much better, thank you very much. :)


With best regards

Clemens Anhuth

Return to “Common Problems”