4
votes

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
2
Temporary files during installation is a "deployment smell". What are these files doing? There are likely better ways that will be simpler for you. - Stein Åsmul
In case you are not aware, WiX creates a Windows Installer package. (WiX is not involved in the actual installation.) You should research the design principles of Windows Installer. - Tom Blodget
The temporary files are used to configure the config files based on the server they are installed on. The setup is used in our DTAP environment, and are used to automatically install on different machines with different configuration files. All configuration files for all servers in the DTAP environment are included in the setup. And based on the servername, some are used, others not. At the end of the installation, i do not need all config files anymore, and want the directory to be removed. - Dennis
I'm not saying my solution is the best solution, but (sorry for saying this), I'm not asking if what I do is wrong (maybe in your eyes i'm completely stupid to do this like i do this), I'm just asking how to remove a directory with contents after installation. - Dennis

2 Answers

1
votes

UPDATE: Not sure why this was down-voted just now. The summary below is sound advice. Perhaps it is the lack of a sample? I'll add a couple of links. Also: there can be cases where a custom action is needed to tweak service installations, but that is rarely necessary if you design the service properly - WiX also has constructs to help you for common tweaks:


There is generally no need to use custom actions to install and configure services. The built-in MSI features for this are vastly superior due to its full rollback support and extensive feature set. Using custom actions greatly complicates things, adds unnecessary risk and will almost always fail during rollback leaving the system in an invalid state.

There is a learning curve with the MSI tables - there are a lot of options, but in my experience only a few bundles of settings make sense together. Generally stopping and restarting during install and stopping and deleting on uninstall and variations on those. In the past I have added custom actions just to wait whilst the service shuts down properly, but that is just a wait custom action and doesn't change the system. There may be new Wix features for this kind of scenario that I am unaware of.

The MSI tables ServiceInstall and ServiceControl are used to install services. In Wix you deal with the equivalent XML elements: Wix ServiceInstall and Wix ServiceControl and the newer Wix ServiceConfig and Wix ServiceConfigFailureActions.

0
votes

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.