以编程方式安装 MSI 软件包 [英] Programmatically installing MSI packages

查看:25
本文介绍了以编程方式安装 MSI 软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的 C# .NET 应用程序中以编程方式安装给定的 .msi 包,最好使用我的应用程序指定的安装参数(如安装路径、拒绝垃圾软件等).

I would like to install a given .msi package programmatically from my C# .NET application, preferably with the installation parameters that my application specifies (like the installation path, decline crapware, etc.).

我进行了一些搜索,但我并没有真正找到任何有用的东西.最有希望的是这个主题,但我找不到任何Microsoft.Deployment.WindowsInstallerWindowsInstaller.Installer 的那个.

I did some searches, but I haven't really found anything useful. The most promising hit was this topic, but I cannot find any documentation of Microsoft.Deployment.WindowsInstaller or of WindowsInstaller.Installer for that matter.

推荐答案

我发现上面提到的 Deployment Tools Foundation 项目是从 .NET 实现此目的的可靠方法.引用 Microsoft.Deployment.WindowsInstaller.dll 后,使用如下代码安装包:

I find the Deployment Tools Foundation project mentioned above to be a solid way to do this from .NET. Having referenced Microsoft.Deployment.WindowsInstaller.dll, use code like this to install a package:

Installer.SetInternalUI(InstallUIOptions.Silent);
Installer.InstallProduct(msiFilename, "ACTION=INSTALL ALLUSERS=2 MSIINSTALLPERUSER=");

.NET 包装器的文档位于 Program Files 的 Windows Installer XML 安装目录中的 .chm 文件中.该 DLL 的某些部分松散地包装了本机 Windows API,因此文档 here 也很有用,这就是我如何计算出上述代码段中的字符串以适应我的情况.

The documentation for the .NET wrapper is in a .chm file in the Windows Installer XML installation directory in Program Files. Some parts of that DLL loosely wrap the native Windows APIs so the documentation here can be useful as well, which is how I worked out the string in the above snippet to suit my situation.

这篇关于以编程方式安装 MSI 软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆