title: WIX - howto use RemoveFolderEx with On="install" / "both"?
body: <p>I am trying to remove a folder on "install" (and "uninstall"), but the folder is only removed on "uninstall".<br>
  Any hints how this can be done?</p>
  
  <pre><code>&lt;Property Id="PACKAGEFOLDER"&gt;
    &lt;RegistrySearch Root="HKLM" Key="$(var.RegKey)" Type="raw" Id="PKGFOLDER_REGSEARCH" Name="PkgDir" /&gt;
  &lt;/Property&gt;
  
  &lt;Directory Id="TARGETDIR" Name="SourceDir"&gt;
   &lt;Directory Id="ProgramFilesFolder"&gt;
    &lt;Directory Id="PACKAGE" Name="$(var.PkgFolder)"&gt;
     &lt;Component Id="PackagesFiles" Guid="$(var.FilesGUID)"&gt;
      &lt;RegistryValue Root="HKLM" Key="$(var.RegKey)" Name="PkgDir" Type="string" Value="[PACKAGE]" KeyPath="yes" /&gt;
      &lt;util:RemoveFolderEx On="both" Property="PACKAGEFOLDER" /&gt;
     &lt;/Component&gt;
    &lt;/Directory&gt;
   &lt;/Directory&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p>just noticed: 
  if the RegKey is available in registry before installation starts, it will work:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>but if the RegKey is not in registry, log says:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>Is it possible to write the RegKey before the Property "PACKAGEFOLDER" is set?</p>