Windows Installer is the installation and configuration service used by Windows to add and remove applications. (For more information, Wikipedia has a great overview of Windows Installer, covering products, components, setup phases, permissions, etc..) In addition to exposing a rich, native API, Windows Installer comes with
msiexec.exe, a command-line tool that offers fine-grained control over the install/uninstall process.
I wanted to familiarize myself with the use of the Windows Installer API from .NET, so I wrote a wrapper class to expose it to managed applications and then a simple program to exercise it. Unlike
msiexec.exewhich can do all kinds of things, my
ManagedMsiExecsupports only UI-less install and uninstall of a .MSI Windows Installer package (i.e.,
/quietmode). By default,
ManagedMsiExecprovides simple status reporting on the command line and renders a text-based progress bar that shows how each phase is going. In its "verbose" mode,
ManagedMsiExecoutputs the complete set of status/progress/diagnostic messages generated by Windows Installer (i.e.,
/l*) so any problems can be investigated.
Aside: Although I haven't tested
ManagedMsiExecexhaustively, it's fundamentally just a thin wrapper around Windows Installer, so I'd expect it to work for pretty much any MSI out there.
Here's how it looks when run:
Msi.cs, the class containing a set of .NET platform invoke definitions for interoperating with the native
MSI.dllthat exposes Windows Installer APIs. The collection of functions and constants in this file is not comprehensive, but it covers enough functionality to get simple scenarios working. Most of the definitions are straightforward, and all of them have XML documentation comments (via MSDN) explaining their purpose. For convenience, many of the relevant Windows error codes from
winerror.hare exposed by the
ManagedMsiExec.cs, the sample application itself which works by calling the relevant
MsiAPIs in the right order. Conveniently, a complete install can be done in as few as three calls: MsiOpenPackage, MsiDoAction, and MsiCloseHandle (with MsiSetProperty an optional fourth for uninstall or customization). To provide a better command-line experience, the default UI for status reporting is customized via MsiSetInternalUI, MsiSetExternalUI, and MsiSetExternalUIRecord. Implementing the handler for a
MsiSetExternalUIcallback is easy because it is passed pre-formatted strings; parsing record structures in the handler for the
MsiSetExternalUIRecordcallback requires a few more API calls (and a closer reading of the documentation!).
I haven't seen many projects providing a managed wrapper for MSI.DLL
Here's a snap of the Project source;
This looks like a great resource if you need this kind of thing/information...