I would like to give the user the option to delete the configuration data stored in the APPDATA folder on uninstall. I have found this answer but it's quite old. There is another answer in this mailing list but it's even older.
Is there a new way of doing this?
We can delete folder recursively with RemoveFolderEx
. For this we need to add following to our Wix root element:
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"
Borrowed from here
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<Fragment>
<!-- Retrieve the CONFIGFOLDER "remembered" on installation -->
<Property Id="CONFIGFOLDER_PROP" Secure="yes">
<RegistrySearch Id="APPLICATIONFOLDER_REGSEARCH"
Root="HKCU"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)"
Type="raw"
Name="Path" />
</Property>
<Component Id="CleanupConfigurationFolder" Directory="CONFIGFOLDER">
<!--
RemoveFolderEx requires that we "remember" the path for uninstall.
Read the path value and set the CONFIGFOLDER property with the value.
-->
<RegistryValue Root="HKCU"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)"
Name="Path"
Type="string"
Value="[CONFIGFOLDER]"
KeyPath="yes" />
<!-- We need to use CONFIGFOLDER variable here or RemoveFolderEx
will not remove on "uninstall". -->
<util:RemoveFolderEx On="uninstall" Property="INSTALLFOLDER_PROP" />
<!-- Here <RemoveFolder/> if needed -->
</Component>
</Fragment>
</Wix>
And the folder definition:
<!-- Appdata (User data) -->
<StandardDirectory Id="AppDataFolder">
<Directory Id="CONFIGFOLDER" Name="!(loc.Company)"/>
</StandardDirectory>
Unfortunately RemoveFolderEx
does not add the folder to the RemoveFile table, we might get this error:
The directory CONFIGFOLDER is in the user profile but is not listed in the RemoveFile table.
So, as workaround I added following dummy line after it (RemoveFolderEx
)
<!-- Dummy action to track the CONFIGFOLDER in the RemoveFile table -->
<RemoveFolder Id='RemoveConfigurationFolder' Directory='CONFIGFOLDER' On='uninstall' />