I need to allow the user to indicate whether the installer should delete or save the registry key during uninstallation. That's what I'm doing. I have a RemoveRegistryKey component with a Condition element that looks like this:
<Component Id="ID" Guid="GUID" KeyPath="yes" > <Condition></Condition> <RemoveRegistryKey Root="HKLM" Key="Software\PATH_TO_KEY" Action="removeOnUninstall"/> </Component>
It seems to work. If I hardcode the Condition element to 0, the registry key will remain; if I set it to 1, the registry key will be deleted. (There is another component that creates this registry key, but I set its ForceDeleteOnUninstall attribute to be equal.)
Now I need to control this condition with user input during deletion. I have a CA in C # that looks like this:
[CustomAction] public static ActionResult AskUser(Session session) { MessageResult result = session.Message ( InstallMessage.User + (int)MessageBoxIcon.Information + (int)MessageBoxButtons.YesNo, new Record { FormatString = String.Format("Delete registry key?") } ); if (result == MessageResult.Yes) session["DELETEREGKEY"] = "1"; return ActionResult.Success; }
I plan on executing CA with this code:
<CustomAction Id="AskUserCA" BinaryKey="CA_Dll" DllEntry="AskUser" Execute="immediate" /> <InstallExecuteSequence> <Custom Action="AskUserCA" Before="InstallValidate">(REMOVE="ALL") AND (NOT UPGRADINGPRODUCTCODE)</Custom> </InstallExecuteSequence>
And I set the Condition element from the RemoveRegistryKey component as:
<Condition>DELETEREGKEY="1"</Condition>
I also tried DELETEREGKEY = 1 and DELETEREGKEY, but although I received an invitation from CA (it appears after the delete confirmation dialog), and I can see in the log file (when I use logging) that DELETEREGKEY is set to 1, regardless of the answer (Yes or No), the registry key is never deleted. I tried to plan CA before / after other events, but nothing helps.
Why is this condition always evaluated as false? Is there any way to make it work?
Also, is there a better alternative? I was thinking of changing the delete dialog to add a checkbox prompting the user to delete the registry key, but I'm not sure how to do this. I know how to make changes - modify existing dialogs or add new ones - to the installation sequence (I use the modified WixUI_InstallDir sequence), but I cannot figure out how to do this when uninstalling.
Any ideas?