Skip to content

Instantly share code, notes, and snippets.

@Jalalx
Created May 9, 2018 04:54
Show Gist options
  • Save Jalalx/c97c367434310077383308caa24ba809 to your computer and use it in GitHub Desktop.
Save Jalalx/c97c367434310077383308caa24ba809 to your computer and use it in GitHub Desktop.
Describes how to catch msi progress...
// from https://www.codeproject.com/Articles/5773/Wrapping-the-Windows-Installer-2-0-API
IntPtr parent = IntPtr.Zero;
MsiInstallUILevel oldLevel =
MsiInterop.MsiSetInternalUI(MsiInstallUILevel.None |
MsiInstallUILevel.SourceResOnly, ref parent);
MsiInstallUIHandler oldHandler = null;
try
{
oldHandler =
MsiInterop.MsiSetExternalUI(new
MsiInstallUIHandler(_OnExternalUI),
MsiInstallLogMode.ExternalUI, IntPtr.Zero);
Application.DoEvents();
MsiError ret =
MsiInterop.MsiInstallProduct(/* path to .msi */,
/* command line args */);
if (ret != MsiError.Success)
throw new
ApplicationException(string.Format("Failed to install -- {0}", ret));
}
catch (Exception e)
{
Debug.WriteLine("EXCEPTION -- " + e.ToString());
// do something meaningful
}
finally
{
if (oldHandler != null)
MsiInterop.MsiSetExternalUI(oldHandler,
MsiInstallLogMode.None, IntPtr.Zero);
MsiInterop.MsiSetInternalUI(oldLevel, ref parent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment