如何在安装完成前让 MSI 在没有用户交互的情况下重新启动?

How to let MSI reboot without user interaction before installation finished?

我正在使用 Visual Studio 安装程序项目构建 MSI。我的一个要求是在安装完成之前自动重启系统。通过说 'automatically',我的意思是没有客户互动,例如单击一个按钮以触发重新启动。此外,重启应该可以通过 msi 的 /norestart 选项来抑制。

我尝试通过添加 属性 REBOOT = Force 来使用 Orca 编辑 MSI。但是这会弹出一个 yes/no windows 供用户点击。只有在用户单击是后才会重新启动,这不是自动的。

我还尝试调用 Win32 API InitiateSystemShutdownEx 来启动重启。但在这种情况下,我无法通过 /norestart 选项禁用重启。

看看REBOOTPROMPT property

If the REBOOTPROMPT property is set to Suppress (or just S) any reboot performed by the Windows Installer happens automatically without interaction from the user. Setting this property does not initiate a reboot if one is not needed, it only suppresses the display of any prompts for reboots to the user.

顺便说一句,Visual Studio 安装项目的众多缺点之一是它们没有为您提供编写此内容的地方。如果使用 CI 构建,则必须使用 ORCA 或某些脚本对 MSI 进行后期构建。这就像使用 ILDASM 来调整 DLL,因为 VB.NET 不支持某些东西。更优雅的解决方案是使用具有更好 Windows Installer XML 支持的工具,例如 Windows Installer XML.