Search code examples
windows-installerinstallshield

Possible to add default value for a created registry key but do not allow that value to reset on Repair (without custom CA code)?


I am trying to to add default value for a created registry key EDIT: (HKLM) but without allowing that value to reset on Repair, and ideally without having to write any code (I think this is something Windows Installer would have in its toolset)

Here is my solution so far:

  1. Added Component which is in charge of adding (or removing) the registry key. The 'data' for this is simply the name of a property [MYPROPERTY]

  2. Added a Property called MYPROPERTY, this has a value of 1 in the table. It can be changed to 0 by the installing user at the command line.

  3. I added a SetProperty CA for MYPROPERTY with a Condition so that it only runs on first Install and not on things like Repair.

The problem I believe is that I have a value of 1 hardcoded for the MYPROPERTY value in the Property table. Obviously, a Repair will reset it to 1. My question is if there is an alternative way to be looking at this problem. Otherwise, I believe I would have to write custom CA to cache the original value and then restore it after Repair. I guess I am trying to figure out ways of doing things with native Windows Installer instead of code.


Solution

  • Here is what I did, in case this is useful:

    1. Created a Property who's value was the default value for the registry setting
    2. Created an AppSearch to look for the value in the registry and store that in a separate property
    3. Created a SetProperty CA to get the property value which was set by the AppSearch above, and assign its value to the property created in step 1. Then, apply an 'only on repair' condition such as REINSTALL~="ALL"

    This way if the user changed the value to something other than default, it is restored