Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

For items such as user data and other settings, I have handled it in the past by leaving the data on the machine during uninstall. During installation, you can check for such data and if it exists, prompt the user to remove\overwrite that data.

I'll summarize my own findings here.

It looks like setting a property in the Execute Sequence is too late for it to take effect when evaluating conditions. But moving the CA to the UI Sequence is not a good option either because by default uninstalls run in silent mode bypassing UI. There is a way to tweak custom uninstall shortcut and the Add/Remove Programs (ARP) entry to run uninstaller in the full UI mode, but it poses its own hassles, the least of which is having to manually populate ARP registry entries.

The approach I took was to simply delete the registry key programmatically in the same CA invoked during Execute Sequence (so I do not need the RemoveRegistryKey component). To allow silent uninstalls, I also added command-line options to specify whether the registry key should be deleted and whether to show prompt (if the delete key switch is not provided). And by default I keep the registry key. Not very elegant, but seems to do the job.

With respect to suggestions on modifying uninstall dialogs, see WiX 3.7: How to add or update a dialog during uninstall?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top