5

I'm wondering if it's possible to manually run a RemoveFolderEx element from a custom action. I'm guessing probably not but someone may know a way that I'm not aware of.

My problem is I want to run the RemoveFolderEx element but only on an true UNINSTALL however my program executes it when upgrading as I've set it to uninstall before reinstalling.

I tried it via this method Wix: condition on property not working however it didn't work and still ran when doing a reinstall.

The only thing I can think of is being able to manually set a RemoveFolderEx off from a custom action which I know that I run at the correct point and only on a true uninstall. Perhaps my custom action could use a c++ dll and then manually add the command to the MSI interface but if I'm going that far it might just be as well to fully write the deletion logic myself.

Thanks. Neil


EDIT: I finally got this working, here is some example wix to show what I did.

<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>    

The property P.REMOVEDATAFOLDER only gets set on a true uninstall immediately after DATADIR is read from the registry but before the CostInitialize action.

Community
  • 1
  • 1
Neil
  • 5,179
  • 8
  • 48
  • 87

2 Answers2

5

I would use the following approach. Do not condition RemoveFolderEx operation, but use a conditioned custom action to set the appropriate value for the target property.

Ciprian
  • 3,533
  • 1
  • 18
  • 22
  • RemoveFolderEx cannot be conditioned however custom actions can be. So running a conditioned custom action which then called a RemoveFolderEx element would have the behaviour I desire. The question I linked is my attempt at putting a conditon on a component containing a RemoveFolderEx element but this doesn't work as I would like. – Neil Nov 25 '11 at 09:39
  • It is tricky calling the RemoveFolderEx from a custom action. What I propose is more simpler. Leave the RemoveFolderEx unchanged and just set it's property from a custom action. – Ciprian Nov 25 '11 at 09:48
  • Sorry I never understood first time around, this is actually bang on I reckon. I'll try it and get back to you on whether it was successful. – Neil Nov 25 '11 at 10:04
  • Thanks a million, this approach worked a treat. I'll add in my example wix above. – Neil Nov 25 '11 at 10:27
  • 3
    Note that this approach works only because the RemoveFolderEx custom action is smart enough not to process a property that doesn't have a value. In fact, a bug during development deleted a bunch of files in the system32 directory on my test VM. That's why I added the code to skip empty properties. :) It's not something you can generally rely on; many things in MSI, for example, will fail if valid values aren't supplied. – Bob Arnson Nov 26 '11 at 02:57
0

Taking some advice from this question, the condition that denotes uninstall is REMOVE="All" AND NOT UPGRADINGPRODUCTCODE.

Something like this may work:

<Component Id="RemoveMyFolder">
  <Condition> REMOVE="All" AND NOT UPGRADINGPRODUCTCODE </Condition>
  <RemoveFolderEx ... />
</Component>
Community
  • 1
  • 1
Hand-E-Food
  • 12,368
  • 8
  • 45
  • 80
  • 1
    This was my original approach however this would never work because the component would never be installed and hence could never be removed. If you read the question I linked it goes into a lot more detail about this approach. – Neil Nov 25 '11 at 09:36