1

While uninstalling a MSI package, there are a bunch of empty folders which are not removed from the ProgramFiles. Is there a way Wix in which I can make sure all the empty directories are removed after uninstallation along with InstallDir.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Karthikeyan Vedi
  • 1,360
  • 1
  • 11
  • 17

2 Answers2

1

RemoveFile / RemoveFolder: Besides implementing your own custom action (which is not recommended), there is the RemoveFile / RemoveFolder concept. In an MSI file this maps to the RemoveFile table. And in WiX it is implement using the RemoveFile Element and the RemoveFolder Element.

RemoveFolderEx: There is also another element available which is a custom WiX extension in the Util namespace. It is called RemoveFolderEx Element. This element can also remove sub-directories - as explained here. You can find a brief sample here (notice the xmlns:util namespace on top). And there is always github.com to search.

Empty folders: Typically empty folders indicate a component reference problem, or folders created via custom actions or by the application itself during its normal operation. My guess is that the latter is the case for you?


Some Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
1

The folder may be used by another process. If so, you could not delete the folders even manually. In that case, 1st close those processes using custom action and proceed the uninstall. Now folders will be deleted.

If there is no process running but still it is not deleted, then you can follow the below steps.

  1. Use 'RemoveFolder' to delete the folder on uninstall

    <Directory Id="DIR_ID">
        <Component Id="comp_file" Guid="INSERT_GUID_HERE">
            <RemoveFolder Id="FOLDERID" On="uninstall" />
            <File Id="FILEID" Source="file.txt" />
        </Component>
    </Directory>
    

    [OR]

  2. Write a custom action and delete all files and folders. In this way, you can delete the files and folders along with InstallDir.
zett42
  • 25,437
  • 3
  • 35
  • 72
Kathir Subramaniam
  • 1,195
  • 1
  • 13
  • 27
  • Good point, I suppose he could also try to reboot to see if the folders are removed afterwards - if there are locks. – Stein Åsmul Sep 04 '18 at 13:47