1

I have a util:RemoveFolderEx element that I only want to run when the program is being uninstalled. I put it inside its own component then set up a condition on a property as to whether it should be included.

Can anyone explain to me why the following doesn't work?

<Property Id='UNINSTALLMODE' Value="FALSE"></Property>

<DirectoryRef Id="DATADIR">        
    <Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
        <util:RemoveFolderEx On="uninstall" Property="DATADIR" ></util:RemoveFolderEx>
        <Condition>(UNINSTALLMODE="TRUE")</Condition>
    </Component>
</DirectoryRef>

<CustomAction Id="CA.SetUninstallMode" Property="UNINSTALLMODE" Value="TRUE" />

<InstallExecuteSequence>
    <Custom Action="CA.SetUninstallMode" Before="WixRemoveFoldersEx" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>            

I've checked the logs and the custom action correctly sets UNINSTALLMODE to "TRUE" when uninstalling the software. On install and reinstall it is "FALSE". I've tried the custom action to be scheduled Before="WixRemoveFoldersEx" and Before="CostInitialise" which are relevant to the RemoveFoldersEx.

Any help is much appreciated, this is driving me nuts! Neil


EDIT: I updated the wix to this

<Property Id='P.INSTALLMODE' Value='0'></Property>
<Property Id='P.UNINSTALLMODE' Value='0'></Property>

<DirectoryRef Id="DATADIR">        
    <Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
        <util:RemoveFolderEx On="uninstall" Property="DATADIR" ></util:RemoveFolderEx>
        <Condition>(P.INSTALLMODE = 1) OR (P.UNINSTALLMODE = 1)</Condition>
    </Component>
</DirectoryRef>

<CustomAction Id="CA.SetInstallModeToTrue" Property="P.INSTALLMODE" Value='1' />
<CustomAction Id="CA.SetUninstallModeToTrue" Property="P.UNINSTALLMODE" Value='1' />

<InstallExecuteSequence>
    <RemoveExistingProducts Before="InstallInitialize" />            

    <Custom Action="CA.SetInstallModeToTrue" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (NOT PREVIOUSVERSIONSINSTALLED)</Custom>
    <Custom Action="CA.SetUninstallModeToTrue" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>

The custom actions run immediately after the DATADIR value is read from the registry and before the CostInitialize.

Here is what happens in the following situations

  • Install -> condition is met and the component is installed
  • Reinstall -> condition is not met but the component is still uninstalled then reinstalled
  • Uninstall -> condition is met and the component is uninstalled

All I can take from this is that the condition is only applicable for the installation procedure and once a component is installed it is not possible to impose a condition on it for being removed.


EDIT2: Finally got this working by using a property for the removefolderex which is set by a custom action. Seems simple now.

<Property Id='P.REMOVEDATAFOLDER' Secure='yes' />

<DirectoryRef Id="DATADIR">        
    <Component Id="C.RemoveDataFolder" Guid="myguid" KeyPath="yes">
        <util:RemoveFolderEx On="uninstall" Property="P.REMOVEDATAFOLDER" />
    </Component>
</DirectoryRef>

<CustomAction Id="CA.SetDataFolder" Property="P.REMOVEDATAFOLDER" Value='[DATADIR]' />

<InstallExecuteSequence>           
    <Custom Action="CA.SetDataFolder" Before="ValidateProductID" >(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>  
Neil
  • 5,179
  • 8
  • 48
  • 87

1 Answers1

2

The condition of the component, which holds the RemoveFolderEx element, is False on install. This means the component is not installed. If it's not installed, it obviously won't be uninstalled, either. Hence, even if the condition-driving property is True on uninstall, the CA won't run because the component it depends upon was not installed.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • Would the solution then be to try to get the condition to be the following? install=true reinstall=false uninstall=true – Neil Nov 24 '11 at 15:03
  • @Neil Seems like it. I would add upgrading=false to the list: you'd want to keep these file when upgrading to newer version of your application. – Alexey Ivanov Nov 24 '11 at 19:14
  • @AlexeyIvanov Unfortunately this didn't work, I managed to get it so I had two properties INSTALLMODE and UNINSTALLMODE. When running an upgrade it uninstalls then reinstalls, both properties were false but it still ran the removefolderex part and deleted everything. I think I'm going to have to admit defeat and just use a custom dll action to delete all the files and folders that I need to. – Neil Nov 24 '11 at 22:43
  • @Neil The verbose log of installation could provide the details on the property values and the actions run, it may help. Of course to delete everything, you can use a CA in DLL or even in JScript/VSScript, yet the disadvantage is that you can't put the files back if user click Cancel during uninstall. – Alexey Ivanov Nov 25 '11 at 06:09
  • @AlexeyIvanov. Thanks I've been using the verbose logs to see that the properties were set before the RemoveFolderEx command was dealt with. I've updated the question with my latest wix but it appears that what I'm trying to do is out-with the scope of the intended design. – Neil Nov 25 '11 at 09:35