Created
May 9, 2018 04:54
-
-
Save Jalalx/c97c367434310077383308caa24ba809 to your computer and use it in GitHub Desktop.
Describes how to catch msi progress...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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