How do I prevent a file or registry entry from being uninstalled or repaired?

Method 1 - Using a folder or a registry operation

Enable Do not overwrite existing files operation with REMOVE="ALL" condition from the Files and Folders Page - Installer Project for the parent folder containing the files you want to avoid being uninstalled.

In a similar way, for registry keys, enable Preserve key content operation with REMOVE="ALL" condition from Registry Page for the parent key containing the registry values you want to avoid being uninstalled.

ImportantIf you already released a version without using these options but want to prevent a file from being overwritten you could enable its Do not overwrite operation with OLDPRODUCTS condition from the Files and Folders Page - Installer Project. The same operation is also available for a registry key or a folder's contents.

Method 2 - using Never Overwrite or Permanent attributes from Organization Page

OrganizationYou need to modify some of the resource's component attributes, in the "Organization" page.

  • to prevent it from being repaired check the "Never Overwrite" attribute

Caution!If a registry entry is a key resource in its component, it cannot have the "Never Overwrite" attribute enabled.

  • to prevent it from being uninstalled check the "Permanent" attribute

However, this method has some drawbacks. By using it, the resource has to be manually repaired or deleted by the user if it gets corrupted.

As a general idea, it is not recommended to use the installed file to store any user data. The best way would be for the application to create a new file that stores it. At the simplest form, this method would consist of simply creating a copy of the installed file and modifying that.

If the application cannot create the file from scratch it should use the installed file as a template for the files that store the user data, meaning that the application uses the installed files as a starting point. It merges the user data with the template data to create the new file.