【问题标题】:How to show dialog or message box during uninstall in WiX?如何在 WiX 中卸载期间显示对话框或消息框?
【发布时间】:2016-12-02 07:14:29
【问题描述】:

我试图在卸载过程中显示一个对话框或消息框(带有是或否按钮)。
我需要在对话框中设置用户选择的属性(是(真)或否(假))。
这个属性很重要,因为如果用户的回答是“是”,所有文件都将被删除。
我试图在卸载时显示一个自定义对话框,但没有奏效。自定义对话框没有给我错误。它甚至不会出现在详细日志中。

这是自定义对话框:

<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>

和InstallUISequence:

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

我在序列中尝试了 After="MigrateFeatureStates",但也没有用。
在另一个问题中,有人问Stopping display of custom dialog boxes in WiX uninstall 这很有趣,因为所有其他问题都试图做相反的事情。
我不想在自定义操作中执行此操作,因为我想阻止卸载进度并等待用户的回答。
有没有办法做到这一点?
任何帮助,将不胜感激。谢谢!

【问题讨论】:

    标签: wix


    【解决方案1】:

    我在我们制作的 SDK 安装中正是这样做的。我们的想法是,如果用户在 SDK 安装位置进行了任何实际开发,所有内容都将被删除,我们希望确保他们保存他们真正需要的任何内容。

    我没有为这个警告框创建一个新对话框,因为消息框是一个非常明确的概念,并且在所有 Windows 产品中都使用过。

    在产品中,我添加了一个自定义操作,安排在之前实际发生任何事情。

    <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>
    

    在我的自定义操作中,我有

    [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;
    }
    

    在您的情况下,您可以使用 messageboxbuttons.YesNo 代替 OKCancel

    在您的自定义操作中使用return="check",如果您从自定义操作返回 ActionResult.Failure,安装将停止。

    我确实从 wix 引导程序启动了此卸载,但行为应该是相同的。

    【讨论】:

    • 感谢您的回答。我试过你的方法,它奏效了。我使用 MessageBoxButtons.YesNo 并根据用户的选择设置属性。它可以阻止卸载进度并等待令人惊叹的答案。 注意: 如果您使用 C# 自定义操作项目,请不要忘记将 .CA.dll 文件引用到 Product.wxs 中的二进制表。 另一个注意事项: 如果您使用 System.Windows.Forms,那么您必须使用 .NET Framework(支持的最低版本为 1.0),因此请记住,这将不会在操作系统上运行没有 .NET Framework 的系统。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 2015-09-27
    • 2019-09-12
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 2021-01-09
    相关资源
    最近更新 更多