How can I delete folders with randomly generated names on Uninstall?

Problem

My MSI installs a service. The service creates temporary data under an installation folder (INSTALLDIR\Web) to a subfolder with a randomly generated name. When user uninstalls the product, I want to force delete the of these randomly generated subfolders. How can I do this?

Drill Down

The native engine behavior you need comes from the RemoveFiles. The RemoveFile table is not just for files. As mentioned on the MSDN documentation for the table’s Filename column: \

FileName

This column contains the localizable name of the file to be removed. If this column is null, then the specified folder will be removed if it is empty. All of the files that match the wildcard will be removed from the specified directory.

Solution

Use a custom action to dynamically populate rows in the RemoveFiles table.

Content credit also belongs to

  • Carolyn, MSI Team Dev Lead.
  • Hem, MSI Team Dev

You can get other Carolyn and Hem insights about developing for Windows Installer from the Windows Installer Chat Archives

[Author: Robert Flaming]

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at https://www.microsoft.com/info/cpyright.htm.