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

时间:2015-01-08 17:00:54

标签: c# windows-installer

所有!

我在我的C#项目中使用COM对象“Microsoft Windows Installer对象库”以编程方式安装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方法可以自动重启安装。

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

我不确定为什么你在命令行中使用ADMIN事物,因为它与没有重启没有任何关系。我假设你想要一个真正的实际安装而不是管理员安装,所以只需使用与重启的msiexec命令行选项相同:

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

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

仅当需要决定重新启动的Windows Installer时才会起作用。如果设置中的代码显式重新启动或覆盖重新启动,则仍会重新启动。

答案 1 :(得分:0)

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

客户端代码几乎相同:

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