Using the InstallManager.Msi.MsiInstallerSession class

The InstallManager.Msi.MsiInstallerSession class manages the execution of the MSI.
Let’s start with the Constructor

public MsiInstallerSession(string msiFile)

The constructor accepts a string parameter that should be a path to your MSI file and returns an MsiInstallerSession object that can manage the execution of the MIS file.

Now let’s see how we can launch this msi file.

There are 3 methods that can do this:

public void Install(string arguments, MsiInstallLogMode logMode)
public void Install()
public void UnInstall()

All 3 methods are using the MsiInstallProduct method. MSDN says the following about the string szCommandLine parameter of this method.

”This should be a list of the format Property=Setting Property=Setting. For more information, see About Properties.

To perform an administrative installation, include ACTION=ADMIN in szCommandLine. For more information, see the ACTION property.”

This information applies to the arguments parameter of the Install method, since it is passed without change as szCommandLine .

The logMode parameter specifies the types of messages that raise events during the execution of the MSI. For more information see: MsiEnableLog method, its description of the dwLogMode parameter details the available log option. The same options are present in the MsiInstallLogMode enum.

The Install() and Uninstall() methods are shorthands of the same functionality with pre-defined parameters.




Install() “ADDLOCAL=ALL”  Default
Unnstall() “REMOVE=ALL” Default

The default log mode is:

MsiInstallLogMode.FatalExit | MsiInstallLogMode.Error | MsiInstallLogMode.Warning |
MsiInstallLogMode.User | MsiInstallLogMode.ActionStart | MsiInstallLogMode.ActionData |
MsiInstallLogMode.CommonData | MsiInstallLogMode.PropertyDump | MsiInstallLogMode.Progress |
MsiInstallLogMode.ShowDialog | MsiInstallLogMode.ExternalUI

Now that we can start an MSI file let’s see how can we capture the details of the execution. During install or uninstall the MSI will send messages to the MsiInstallerSession instance, these messages will in turn raise events on the instance.

public event EventHandler OnMsiMessage;
public event EventHandler OnShowDialogMessage;
public event EventHandler OnInitializeMessage;
public event EventHandler OnCommonDataMessage;
public event EventHandler OnProgressMessage;
public event EventHandler OnActionDataMessage;
public event EventHandler OnActionStartMessage;
public event EventHandler OnOutOfDiskSpaceMessage;
public event EventHandler OnFilesInUseMessage;
public event EventHandler OnInfoMessage;
public event EventHandler OnUserMessage;
public event EventHandler OnWarningMessage;
public event EventHandler OnErrorMessage;
public event EventHandler OnFatalErrorMessage;
public event EventHandler OnTerminateMessage;

The OnMsiMessage event is raised on every message. The other events are raised only when their respective type of messages are raised. For the type of messages available see here.

You can signal back to the running MSI by setting the ReturnValue of the MsiEventargs. For the possible values and their effect see here and here.

Some of the messages can be parsed further and into more useful objects.


Can be Parsed As


MsiInstallMessage.Progress MsiProgressMessage MsiProgressMessage pm = new MsiProgressMessage(message);
MsiInstallMessage.ActionStart MsiActionMessage new MsiActionMessage(message);
MsiInstallMessage.CommonData MsiCommonDataMessage var msg = MsiCommonDataMessage.Parse(p)

For examples on how to wire up and handle a session in detail see the sample projects.


~ by baloghp on August 14, 2012.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: