简体   繁体   English

MSI:在安装的UI阶段显示消息框

[英]MSI: Show message box in UI phase of installation

I'm updating an InstallShield based installer. 我正在更新基于InstallShield的安装程序。 I've added a new managed custom action, written in C#, and packaged using Wix DTF. 我添加了一个新的托管自定义操作,该操作用C#编写,并使用Wix DTF打包。 Action is invoked correctly, and performs necessary actions. 操作将被正确调用,并执行必要的操作。

Problem I have is showing an error message to user. 我遇到的问题是向用户显示错误消息。

Method 1: MsiProcessMessage 方法1: MsiProcessMessage

From articles I've read, I understood that MsiProcessMessage is the correct way to do it, however this method does not work in UI sequence (before setup actually starts copying files and modifying system). 从我读过的文章中,我了解到MsiProcessMessage是执行此操作的正确方法,但是此方法不适用于UI序列(在安装程序实际开始复制文件和修改系统之前)。 In install sequence this method works. 在安装顺序中,此方法有效。 Code which I use is following: 我使用的代码如下:

Record record = new Record() { FormatString = "Password is not valid for this user." };
session.Message(
    InstallMessage.Error | (InstallMessage)(MessageBoxIcon.Error) | (InstallMessage)MessageBoxButtons.OK,
    record
);

Is it actually impossible to show an error message in UI sequence (Immediate execution) using MsiProcessMessage ? 使用MsiProcessMessage以UI顺序(立即执行)显示错误消息实际上是不可能的吗?

Method 2: MessageBox.Show 方法2: MessageBox.Show

Using Windows.Forms works for showing a message box. 使用Windows.Forms可显示消息框。 However, message is displayed in background of setup wizard, and shows a separate icon in Windows taskbar. 但是,消息显示在安装向导的背景中,并在Windows任务栏中显示一个单独的图标。

Is there a way to get window handle of installation wizard, and that way solve this problem? 有没有一种方法可以获取安装向导的窗口句柄,并且可以解决此问题?

You didn't quite mention this, but I'm guessing that you are invoking your custom action off a DoAction ControlEvent , published off of something like a button click. 您并未完全提及,但是我猜您正在从DoAction ControlEvent调用自定义动作,该动作是通过单击按钮等内容发布的。 Underneath the covers, this is very different from scheduling it in the InstallUISequence . 在幕后,这与在InstallUISequence中对其进行调度非常不同。 MsiProcessMessage doesn't work from DoAction . MsiProcessMessage在DoAction中不起作用

For proper integration with the Windows Installer UI experience, you should avoid using MessageBox.Show (your method 2). 为了与Windows Installer UI体验正确集成,应避免使用MessageBox.Show(方法2)。 Better-integrated options include: 更好的集成选项包括:

All three of those involve editing the UI of your project, but differently. 所有这三个都涉及编辑项目的UI,但方式有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM