【问题标题】:How do I show Error Message using Managed Custom Actions with Windows Installer如何在 Windows Installer 中使用托管自定义操作显示错误消息
【发布时间】:2008-12-16 12:46:59
【问题描述】:

我正在编写托管自定义操作。我正在使用 Windows Installer Xml 中的 DTF 框架将托管 dll 包装到可用的 CA dll 中。 CA 做了它应该做的事,但我仍然无法处理错误:

Dim record As New Record(1)

' Field 0 intentionally left blank
' Field 1 contains error number
record(1) = 27533
session.Message(InstallMessage.Error, record)

以上代码在 MSI 日志中生成以下文本:

MSI (c) (C4 ! C6) [13:15:08:749]:产品:TestMSI -- 错误 27533。区分大小写的密码不匹配。

错误编号是指包含在 MSI 中的错误表中的代码。上面显示的消息是正确的。

我的问题是:为什么 Windows Installer 没有创建一个对话框来通知用户错误?

【问题讨论】:

    标签: error-handling windows-installer managed custom-action


    【解决方案1】:

    MSI 可以做到这一点,但您需要为 messageType 参数添加一些额外的值。

    例如。

    Record record = new Record();
    record.FormatString = string.Format("Something has gone wrong!");
    
    session.Message(
        InstallMessage.Error | (InstallMessage) ( MessageBoxIcon.Error ) |
        (InstallMessage) MessageBoxButtons.OK,
        record );
    

    有关详细信息,请参阅 wix-users 邮件列表中的this thread

    【讨论】:

      【解决方案2】:

      根据Wix:Nick Ramirez 的 Windows Installer XML 开发人员指南,我遇到了同样的问题,当从 UI 控件调用自定义操作时,日志和消息方法不起作用。

      【讨论】:

        【解决方案3】:

        如果您希望显示包含该消息的对话框,您必须自己完成。

        下面是一些我用来在运行 SQL 的托管自定义操作中进行错误处理的代码。 如果安装使用完整的 UI 运行,它会显示一个消息框。 它在 c# 中,但希望你能明白。

            private void _handleSqlException(SqlException ex)
            {
                StringBuilder errorMessage = new StringBuilder();
                errorMessage.Append("A SQL error has occurred.");
                for (int i = 0; i < ex.Errors.Count; i++)
                {
                    errorMessage.Append("Index #" + i + "\n" +
                        "Message: " + ex.Errors[i].Message + "\n" +
                        "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                        "Source: " + ex.Errors[i].Source + "\n" +
                        "Procedure: " + ex.Errors[i].Procedure + "\n");
                }
                session.Log(errorMessage);
                if (session["UILevel"] == "5")
                {
                    MessageBox.Show(errorMessage);
                }
            }
        

        【讨论】:

        • 这不是最广泛接受的方法,因为消息窗口可能会出现在安装程序后面,并且我认为会以不同的权限启动
        猜你喜欢
        • 2011-03-15
        • 1970-01-01
        • 2021-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-06
        相关资源
        最近更新 更多