Kayra Levent
Kayra Levent

Reputation: 73

How to show dialog or message box during uninstall in WiX?

I'm trying to show a dialog or message box(with yes or no buttons) during uninstall.
I need to set a property with user's choice from my dialog (Yes(true) or No(false)).
This property is important because all the files are going to be deleted if user's answer is "Yes".
I tried to show a custom dialog on uninstall and that didn't work. Custom dialog didn't give me an error. It doesn't even appear in the verbose log.

Here is the custom dialog:

<Dialog Id="ClearAllDataDlg" Width="260" Height="85" Title="[Setup] - [ProductName]" NoMinimize="yes">
    <Control Id="No" Type="PushButton" X="132" Y="57" Width="56" Height="17" Default="yes" Cancel="yes" Text="[ButtonText_No]">
      <Publish Property="CLEARALLDATA" Value="0" />
      <Publish Event="EndDialog" Value="Return">1</Publish>
    </Control>
    <Control Id="Yes" Type="PushButton" X="72" Y="57" Width="56" Height="17" Text="[ButtonText_Yes]">
      <Publish Property="CLEARALLDATA" Value="1" />
      <Publish Event="EndDialog" Value="Exit">1</Publish>
    </Control>
    <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="30">
      <Text>Do yo want to clear all data including your settings?</Text>
    </Control>
    <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="[InfoIcon]" />
  </Dialog>

and the InstallUISequence:

<Show Dialog="ClearAllDataDlg" Before="CostFinalize">REMOVE ~= "ALL"</Show>

I tried After="MigrateFeatureStates" in the Sequence but that didn't work either.
In another question somebody asked Stopping display of custom dialog boxes in WiX uninstall that is funny because all the other questions are trying to do it's opposite.
I don't want to do this inside of a custom action because i want to block the uninstall progress and wait for the user's answer.
Is there any way to accomplish this?
Any help would be appreciated. Thank you!

Upvotes: 6

Views: 3075

Answers (1)

Brian Sutherland
Brian Sutherland

Reputation: 4798

I do exactly this in a SDK install we produce. The idea being that if the user has done any actual development inside the SDK install location everything is getting deleted and we want to make sure they save anything they really need.

I didn't create a new dialog for this warning box because a message box is a very well-defined and used concept in all windows products.

In product I added a custom action scheduled before anything actually happens.

<CustomAction Id='CA_UninstallWarning' BinaryKey='SDKCustomActionsDLL' DllEntry='UninstallWarning' Execute='immediate' Return='check' />

<InstallExecuteSequence>
    <Custom Action='CA_UninstallWarning' Before='FindRelatedProducts'>NOT UPGRADINGPRODUCTCODE AND REMOVE~="ALL"</Custom>
    ...
</InstallExecuteSequence>

And in my custom action I have

[CustomAction]
public static ActionResult UninstallWarning(Session session)
{
    session.Log("Begin UninstallWarning.");

    Record record = new Record();
    record.FormatString = session["WarningText"];

    MessageResult msgRes = session.Message(InstallMessage.Warning | (InstallMessage)System.Windows.Forms.MessageBoxButtons.OKCancel, record);

    session.Log("End UninstallWarning.");

    if (msgRes == MessageResult.OK)
    {
        return ActionResult.Success;
    }

    return ActionResult.Failure;
}

In your case you can use messageboxbuttons.YesNo instead of OKCancel

With return="check" in your custom action, the installation will stop if you return ActionResult.Failure from the custom action.

I do have this uninstall launching from a wix bootstrapper but the behaviour should be the same.

Upvotes: 7

Related Questions