在通过 visual c# app 执行的 msi 安装上指定 norestart

Specify norestart on msi installation executed through visual c# app

所有!

我在我的 C# 项目中使用 COM 对象 "Microsoft Windows Installer Object Library",以编程方式安装 MSI 包:

using System;
using WindowsInstaller;

private static void InstallCOM(string msiPackage)
{
    Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
    Installer installer = (Installer) Activator.CreateInstance(type);
    installer.UILevel = MsiUILevel.msiUILevelNone;

    installer.InstallProduct(msiPackage, "ACTION=ADMIN");
}

。但我不知道如何使这个自动的、不可重启的安装。此 InstallCOM 方法执行自动、可重新启动的安装。

感谢您的帮助!

我不确定您为什么在命令行中使用 ADMIN 东西,因为它与不重新启动无关。我假设你想要一个真正的真正安装而不是管理员安装所以只需使用与 REBOOT 的 msiexec 命令行选项相同的选项:

http://msdn.microsoft.com/en-us/library/aa371101(v=vs.85).aspx

所以你会在命令行中说 REBOOT=ReallySuppress。

只有当 Windows 安装程序决定需要重新启动时,它才会起作用。如果设置中有明确重启或覆盖重启的代码,那么仍然会重启。

Windows 安装程序 COM 自动化接口中存在许多缺陷,这些缺陷会导致从托管代码调用它时出现问题。我建议改用 Microsoft.Deployment.WindowsInstaller.dll(在 Windows 安装程序 XML 中找到)。这是一个写得很好的互操作库,它包装了 Windows Installer Win32 API 函数。

客户端代码几乎相同:

using Microsoft.Deployment.WindowsInstaller;
Installer.InstallProduct(msiPackage, "REBOOT=R");