1
votes

Hi there I am having a problem getting my Wix installer to remove elements on Uninstall. The problem folders and files are located on our corporate specified programdata folder 'D:\programdata'. The folders get created OK, however will not remove on Uninstall. The folder structure is as follows

 D:\programdata
      Company Name
        App Name
          Logs
          QueryOutput

The following is an excerpt from the relevant section of the product.wxs file:

 <Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="CommonAppDataFolder" Name="CommonAppData" >
    <Directory Id="dirCompanyAppData" Name="Company Name">
      <Directory Id="dirAppNameAppData" Name="AppName">
        <Component Id="cmpDirCommonAppData" Guid="{F808944A-D898-43F3-BA1D-A35A3FD7DF41}" KeyPath="yes">
          <CreateFolder Directory="dirAppNameAppData" />
          <RemoveFile Id="PurgeAppName" Name="*.*" On="uninstall" />
          <RemoveFolder Id="idDirAppNameAppData" On="uninstall" Directory="dirAppNameAppData" />
        </Component>
      </Directory>
      <Component Id="cmpDirCompanyName" Guid="{A1E7E75A-D582-40C5-BD6B-D36BFB11795E}" KeyPath="yes">
        <RemoveFile Id="PurgeCompanyName" Name="*.*" On="uninstall" />
        <RemoveFolder Id="idDirCompanName" On="uninstall" Directory="dirCompanyNameAppData" />
      </Component>          
    </Directory>
  </Directory>
  <Directory Id="ProgramFilesFolder">
  ... etc

Note company and application identifying elements have been replaced in the code. I have left out the remainder of the wxs file for brevity and because I believe the relevent code is included in this extract. Any assistance much appreciated, this has me stumped.

Kind Regards Paul J.

1

1 Answers

0
votes

From RemoveFolder definition:

Remove an empty folder if the parent component is selected for installation or removal.

In your case the AppData folder probably has user specific configuration in it like it is supposed to.

I think all the component planning is done first, then executed. So, RemoveFile will plan all the files in that folder to be removed and RemoveFolder will decide it shouldn't delete the folder because at the time of planning, the folder still has stuff in it that is not part of the installation included components and therefore not empty.

You will need to use util:RemoveFolderEx. Again there is another caveat to using this.

Because it might dramatically affect Windows Installer's File Costing, the temporary rows must be written before the CostInitialize standard action. Unfortunately, MSI doesn't create properties for the Directory hierarchy in your package until later, in the CostFinalize action.

So you need to manually set a directory based off of a property you probably read from the registry before the WixRemoveFoldersEx action which I think is scheduled just before CostInitialize.