以编程方式安装 MSI 软件包

Programmatically installing MSI packages(以编程方式安装 MSI 软件包)
本文介绍了以编程方式安装 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 软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)