Set default values in registry, if there are none
wix
Solution
Start with the Wix Remember Property pattern but take it one step farther. After `AppSearch` runs and the `REMEMBERME` property does or doesn't get a value, use a `SetProperty` custom action to assign a default value if `REMEMBERME=""`.
I take it one step farther though. I have a concept I call "property precedence". Basically it's a list of priorities for how a property should get it's value.
Highest to lowest:
- properties inputted during the UI
- public properties passed in at the command line
- Properties found during `AppSearch`
- Default values defined in the `Property` table
In other words, during a first time silent install with no properties passed at the command line the default value in the property table should be used.
During a second time silent install with no properties passed at the command line, the remembered value should take priority over the default value. (If different)
During a first of second silent install, a property passed at the command line should be considered an override value and take priority over both the default and remembered value.
During an interactive install the above rules take place and the UI should display that value. If the user changes the value then this is the ultimate value.
I'll leave it up to you of how to implement the various custom actions to do this. It generally involves a temp prop and a real prop and a series of Set Property CA's with the right execution scheduling and conditions to do what you want it to do.
Problem
I am maintaining an old application in which the users configuration is stored in registry. It is left behind when uninstalling. I am now re-writing the installer in WiX. The installer should add a default value in the registry if there are none there, otherwise the existing value should be left alone. I was thinking on how to do this in WiX. And the solution I came up with is somewhat cumbersome: ``` <Property Id="MY_PROPERTY"> <RegistrySearch Root="HKLM" Key="SOFTWARE\MyProduct" Name="MyProperty" Type="raw" /> </Property> <CustomAction Id="ca.SetDefaultValue" Property="MY_PROPERTY" Value="DefaultValue" /> <InstallExecuteSequence> <Custom After="RegistrySearch" Action="ca.SetDefaultValue">Not MY_PROPERTY</Custom> </InstallExecuteSequence> <Component Id="c.Registry"> <RegistryValue Root="HKLM" Key="SOFTWARE\MyProduct" Name="MyProperty" Type="string" Value="[MY_PROPERTY]" /> </Component> ``` So do a registry search to find old value. If not set, set to default value using a scheduled custom action. Then create the value "as usual". Anyone who can think up a smoother way to do this? Note that I cannot use convenient variables like `Installed` since values might be there, left behind by a previous, now uninstalled, version.