Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WiX 3.7: How to delete registry key on uninstall based on condition set by user?

I need to allow a user to specify whether the installer should remove or retain a registry key during uninstallation. Here is what I do. 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>

This seems to work as expected. If I hard code the Condition element to 0, the registry key stays, if I set it to 1, the registry key gets removed. (There is a different component that creates this registry key, but I set its ForceDeleteOnUninstall attribute to no.)

Now, I need to control this condition via user input during uninstallation. 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 schedule CA execution using 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 of the RemoveRegistryKey component as:

<Condition>DELETEREGKEY="1"</Condition>

I also tried DELETEREGKEY=1 and DELETEREGKEY, but even though I get the prompt from the CA (it appears after the uninstall confirmation dialog box) and I can see in the log file (when I use logging) that DELETEREGKEY is set to 1, regardless of response (Yes or No), the registry key is never deleted. I tried scheduling the CA before/after other events, but nothing seems to help.

Why does this condition seem to always evaluate to false? Is there a way to make it work?

Also, is there a better alternative? I was thinking about modifying the uninstall dialog to add a check box prompting 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 install sequence (I'm using a modified WixUI_InstallDir sequence), but I can't figure out how to do it on uninstall.

Any ideas?

like image 304
Alek Davis Avatar asked Sep 27 '13 23:09

Alek Davis


1 Answers

Normally you schedule dialog's in the UI-Sequence and not in Execute Sequence. When you are not doing this, you can't have a silent (un)-install.

I think your CustomAction (CA) is run to late and the script which will executed is already created. DELETEREGKEY in this case is unset and evaluates to false - result Key stays.

Try to move your CA to UI-Sequence, please.

like image 105
coding Bott Avatar answered Sep 27 '22 20:09

coding Bott