Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove directory and files after installation using Wix

During installation i need some extra files in Custom Actions that are configured in the InstallExecuteSequence tag asl After="InstallFinalize".

After the usage of the files, i want the files (and the directory) to be removed.

How can i do this?

My InstallExecuteSequence lookst like this:

  <InstallExecuteSequence>
     <Custom Action="UNINSTALLSERVICE"
             After="InstallInitialize">REMOVE="ALL"</Custom>
     <Custom Action="CLEANUP"
             Before="RemoveFiles">REMOVE="ALL"</Custom>
     <Custom Action="INSTALLSERVICE"
             After="InstallFinalize" />
  </InstallExecuteSequence>

If i create a custom action with

ExeCommand="cmd /C RD "somedir" /s /q"

and add it to the sequence like this:

 <Custom Action="CLEANTEMP" After="InstallFinalize" />

I get a build-error:

Error   596 ICE77: CLEANCONFIG is a in-script custom action.  
It must be sequenced in between the InstallInitialize action 
and the InstallFinalize action in the InstallExecuteSequence table
like image 419
Dennis Avatar asked Nov 01 '22 20:11

Dennis


1 Answers

There are many problems with the way you seem to have set up things:

  • Custom actions after InstallFinalize are not to change the system, and they will not be able to run with admin rights. In addition you have set the custom action to be deferred mode, and this is only allowed between InstallInitialize and InstallFinalize - which is what the error message you refer to is about.
  • Some people use immediate mode custom actions after InstallFinalize. This is by definition always an error, and will only work if the entire setup is run with admin rights. Even then it will most often fail when distributed with SCCM or other software distribution systems in the corporate world.
  • Using temporary files during installation is generally undesirable. It is a "deployment smell" as I commented above. Some uses are OK, such as displaying logos and license agreements, but these also tend to be compiled into the setup and removed automagically.
  • Running batch files as part of installation is very unreliable and error prone, and may make changes to the system that can not be rolled-back should the setup fail during installation.

The RemoveFile table (Wix equivalent) will allow you to remove files during installation, uninstallation or both. You should not remove files that are part of an associated Windows Installer component, as self-repair may put them back.

I believe, that what you need is:

  1. A serious rethink of your use of batch files and temporary files. Most likely they are more trouble than they are worth.
  2. A full understanding of elevated rights and Windows Installer's security model and the difference between immediate mode (user rights) and deferred mode (elevated rights) custom actions. Here is a good article by a recognized MSI expert. Update 2021-09-04: Original link appears to be dead. Here is the link via Archive.org.
like image 119
Stein Åsmul Avatar answered Jan 04 '23 15:01

Stein Åsmul