Tuesday, December 6, 2011

How to delete installed files on rollback

Sometimes you have an InstallShield project that installs additional files using SUPPORT FILES. If such installer fails for some reason, your support files won't necessarily be deleted.
There are multiple ways to achieve this. One would be to write an InstallScript method that removes the files you installed. Call this method from your Custom Action (using InstallScript Custom Action) and set it to execute only during Rollback Installation.
In order to do this, you can simply run the Custom Action Wizard.
  • Start the wizard by going to Custom Actions and Sequences and right click and select Custom Action Wizard. 
  • Let's suppose your InstallScript method that cleans up the files is CleanupOnRollBack(), in the wizard, give the same name for the custom action i.e. CleanupOnRollBack. Click Next. 
  • Select the type as 'Run Installscript code'. Click Next. 
  • In source, list of Installscript functions will be populated, select the CleanupOnRollBack(). Click Next. 
  • Under 'Return Processing' select 'Synchronous (Ignores exit code)'. Click Next. 
  • Under 'In-Script' execution, select 'Rollback Execution'. Click Next. 
  • On Next Screen you can leave Install UI Sequence as 'Absent from Sequence' and select Install Execute Sequence as 'After InstallInitialize'. You can change any other event as per your requirements. 
  • Click Next and Finish. 

Here is a sample that you can use.

 This sample just attempts to install one text file and if Install fails (which will because I have added a SQL Connection and an invalid SQL script 'Select * from test' which won't get executed successfully), the rollback will occur and RollBack method gets called.

All you need is to write the InstallScript code to remove the correct files as per your requirements. I have added some commented sample code that might help you.

The sample was built with InstallShield 2012 Pro trial version so you should be able to run it if you get the same.

No comments:

Post a Comment