WIX - howto use RemoveFolderEx with On="install" / "both"?

2

I am trying to remove a folder on "install" (and "uninstall"), but the folder is only removed on "uninstall".
Any hints how this can be done?

<Property Id="PACKAGEFOLDER">
  <RegistrySearch Root="HKLM" Key="$(var.RegKey)" Type="raw" Id="PKGFOLDER_REGSEARCH" Name="PkgDir" />
</Property>

<Directory Id="TARGETDIR" Name="SourceDir">
 <Directory Id="ProgramFilesFolder">
  <Directory Id="PACKAGE" Name="$(var.PkgFolder)">
   <Component Id="PackagesFiles" Guid="$(var.FilesGUID)">
    <RegistryValue Root="HKLM" Key="$(var.RegKey)" Name="PkgDir" Type="string" Value="[PACKAGE]" KeyPath="yes" />
    <util:RemoveFolderEx On="both" Property="PACKAGEFOLDER" />
   </Component>
  </Directory>
 </Directory>
</Directory>

just noticed: if the RegKey is available in registry before installation starts, it will work:

WixRemoveFoldersEx: Recursing path: C:\Program Files (x86)... for row: wrf945C37509CA5EEDC2367957D5F072DFF. MSI (s) (94!A8) [19:17:55:185]: PROPERTY CHANGE: Adding _UNOPACKAGEFOLDER_0 property. Its value is 'C:\Program Files (x86)... MSI (s) (94:D4) [19:17:55:185]: Doing action: CostInitialize

but if the RegKey is not in registry, log says:

WixRemoveFoldersEx: Error 0x80070057: Missing folder property: APPLICATIONFOLDER for row: wrfA308D08284221970F6338358BFB75917 CustomAction WixRemoveFoldersEx returned actual error code 1603 but will be translated to success due to continue marking MSI (s) (84:50) [19:29:08:529]: Doing action: CostInitialize

Is it possible to write the RegKey before the Property "PACKAGEFOLDER" is set?

wix
asked on Stack Overflow Mar 3, 2014 by oli_b • edited Mar 5, 2014 by Yan Sklyarenko

2 Answers

0

I assume that you have also files in this folder that should be deleted. If there are no (arbitrary) subdirectories containing files it should be straight forward by using the RemoveFile-table of the Windows Installer. As it will only delete the folder if it is empty, add an additional entry that will delete the files in it, e.g.:

<Directory Id="TARGETDIR" Name="SourceDir">
 <Directory Id="ProgramFilesFolder">
  <Directory Id="PACKAGE" Name="$(var.PkgFolder)">
   <Component Id="PackagesFiles" Guid="$(var.FilesGUID)">
    <RegistryValue Root="HKLM" Key="$(var.RegKey)" Name="PkgDir" Type="string" Value="[PACKAGE]" KeyPath="yes" />
    <RemoveFile Id="RemovePACKAGEFolderFiles" Directory="PACKAGE" Name="*.*" On="both" />
    <RemoveFolder Id="RemovePACKAGEFolder" Directory="PACKAGE" On="both" />
   </Component>
  </Directory>
 </Directory>
</Directory>

This way you don't have to deal with any property setting. If you have other subdirectories with files you would have to repeat this also for these.

Another way would be to create a deferred custom action in the system context that will delete the folder completely, e.g. in VBScript.

answered on Stack Overflow Mar 5, 2014 by taffit
0

If you add <SetProperty Id="PACKAGEFOLDER" Value="[PACKAGE]" After="CostFinalize" />, you can get the value of package during install. From this article regarding property-setting.

answered on Stack Overflow Aug 30, 2018 by Alexander

User contributions licensed under CC BY-SA 3.0