编程方式安装MSI包方式、MSI

2023-09-02 21:35:56 作者:假装!

我想以编程方式从我的C#.NET应用程序,preferably安装一个给定的.msi包的安装参数,我的应用程序指定(如安装路径,下降crapware,等等)。

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

我做了一些搜索,但我还没有真正发现任何有用。最有前途的命中是this话题,但我无法找到 Microsoft.Deployment.WindowsInstaller WindowsInstaller.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.

能否请你点我正确的方向?

Could you please point me to the right direction?

推荐答案

我发现上面提到的是实实在在地从.NET做到这一点的部署工具基金项目。经参考Microsoft.Deployment.WindowsInstaller.dll,使用code这样的安装包:

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包装是在程序文件的Windows安装程序XML安装目录中的.chm文件。该DLL的某些部分松散包装原生的Windows API,以便在文档的这里可能是有用的,这是我摸索出字符串在上面的代码片段,以适应我的情况。

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.