Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically installing MSI packages

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.).

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.

like image 768
ShdNx Avatar asked Apr 23 '11 14:04

ShdNx


People also ask

How would you start to install an MSI package silently?

If you are looking for complete silence then you also need the MSI to run in quiet mode. You achieve this by running the msiexec.exe with the /qn switch. This switch means quiet and no interface.


1 Answers

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=");

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.

like image 174
Stephen Hewlett Avatar answered Sep 21 '22 20:09

Stephen Hewlett