WiX 3.7: How to delete a registry key upon deletion based on a condition set by the user?

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?

+7
source share
3 answers

Usually, you plan dialogue in a UI sequence, not in a run sequence. When you do not, you cannot remain silent (un) -install.

I think your CustomAction (CA) started too late, and the script to be executed has already been created. DELETEREGKEY in this case is not set and evaluates to false - the result is the Key remains.

Try moving your CA to UI-Sequence, please.

+5
source

For elements such as user data and other parameters, I processed it in the past, leaving data on the machine during deletion. During installation, you can check such data, and if it exists, suggest the user to delete / rewrite this data.

+1
source

I will summarize my findings.

It seems that setting the property in the Execute Sequence is too late for it to take effect when evaluating the conditions. But moving the CA to the user interface sequence is not a good option, because by default uninstalls starts silently, bypassing the interface. There is a way to configure a custom uninstall shortcut and the Add or Remove Programs (ARP) entry to run the uninstaller in full user interface mode, but it creates its own problems, the least of which has to be manually filled in with ARP registry entries.

The approach I took was to simply delete the registry key programmatically in the same CA that was called during the execution of the execution sequence (so I do not need the RemoveRegistryKey component). To allow silence, I also added command-line options to indicate whether to remove the registry key and show a prompt (if the delete key switch is not specified). And by default, I keep the registry key. Not very elegant, but seems to do the job.

For suggestions on modifying uninstall dialogs, see WiX 3.7: How do I add or update a dialog during uninstall?

0
source

Source: https://habr.com/ru/post/954822/


All Articles