void UpdateStatus() { var msi = new MsiParser(MsiFile); IsCurrentlyInstalled = msi.IsInstalled(); ProductName = msi.GetProductName(); ProductVersion = msi.GetProductVersion(); ProductStatus = string.Format("The product is {0}INSTALLED\n\n", IsCurrentlyInstalled ? "" : "NOT "); }
static public void Main() { string msiFile = @"E:\Galos\Projects\WixSharp\Main\WixSharp.Samples\Wix# Samples\_CustomDialog\External_CLR_GUI\MsiInterop\MyProduct.msi"; string msiParams = ""; //install msiParams = "REMOVE=ALL"; //uninstall var msi = new MsiParser(msiFile); var productCode = msi.GetProductCode(); bool installed = msi.IsInstalled(); //IntPtr product; //MsiExtensions.Invoke(() => MsiInterop.MsiOpenProduct(productCode, out product)); Console.WriteLine("The product is {0}INSTALLED\n\n", installed ? "" : "NOT "); if (installed) msiParams = "REMOVE=ALL"; //uninstall else msiParams = ""; //install var session = new MsiSession(); session.Execute(msiFile, msiParams); }
/// <summary> /// Called when MSI message is received. It is actual the MSI <c>Message Loop</c>. /// </summary> /// <param name="message">The message data.</param> /// <param name="messageType">Type of the message.</param> /// <returns>The integer as per MSI documentation.</returns> protected virtual int OnMessage(string message, MsiInstallMessage messageType) { try { switch (messageType) { case MsiInstallMessage.ActionData: this.OnActionData(message); return((int)DialogResult.OK); case MsiInstallMessage.ActionStart: this.CurrentActionName = message.Substring(message.LastIndexOf(".") + 1); return((int)DialogResult.OK); case MsiInstallMessage.CommonData: string[] data = MsiParser.ParseCommonData(message); if (data != null && data[0] != null) { switch (data.MSI <int>(1)) { case 0: // language { Language = data.MSI <int>(2); CodePage = data.MSI <int>(3); } break; case 1: // caption { Caption = data.MSI <string>(2); } break; case 2: // CancelShow { CanCancel = data.MSI <int>(2) == 1; } break; default: break; } } return((int)DialogResult.OK); case MsiInstallMessage.Error: OnError(message, false, MsiInstallMessage.Error); return(1); case MsiInstallMessage.FatalExit: OnError(message, true, MsiInstallMessage.FatalExit); return(1); case MsiInstallMessage.FilesInUse: // display in use files in a dialog, informing the user // that they should close whatever applications are using // them. You must return the DialogResult to the service // if displayed. { //If locked files need to be reported to the user then MsiSetExternalUIRecord should be used OnError("Files in use", true, MsiInstallMessage.FilesInUse); return(0); // we didn't handle it in this case! } case MsiInstallMessage.Info: this.OnInfo(message); return(1); case MsiInstallMessage.Initialize: return(1); case MsiInstallMessage.OutOfDiskSpace: { OnError("Out Of Disk Space", true, MsiInstallMessage.OutOfDiskSpace); break; } case MsiInstallMessage.Progress: { string[] fields = MsiParser.ParseProgressString(message); if (null == fields || null == fields[0]) { return((int)DialogResult.OK); } switch (fields.MSI <int>(1)) { case 0: // reset progress bar { ProgressTotal = fields.MSI <int>(2); IsProgressForwardDirection = fields.MSI <int>(3) == 0; IsProgressTimeEstimationAccurate = fields.MSI <int>(4) == 0; ProgressCurrentPosition = IsProgressForwardDirection ? 0 : ProgressTotal; } break; case 1: // action info { if (this.ProgressTotal == 0) { return((int)DialogResult.OK); //The external handler should not act upon any of these messages until the first a Reset progress message is received. } if (fields.MSI <int>(3) == 1) { TicksPerActionDataMessage = fields.MSI <int>(2); } } break; case 2: // progress { if (this.ProgressTotal == 0) { return((int)DialogResult.OK); //The external handler should not act upon any of these messages until the first a Reset progress message is received. } if (this.ProgressTotal != 0) //initialized { if (IsProgressForwardDirection) { ProgressCurrentPosition = ProgressCurrentPosition + fields.MSI <int>(2); } else { ProgressCurrentPosition = ProgressCurrentPosition - fields.MSI <int>(2); } } } break; default: break; } if (this.CancelRequested) { return((int)DialogResult.Cancel); } else { return((int)DialogResult.OK); } } case MsiInstallMessage.ResolveSource: return(0); case MsiInstallMessage.ShowDialog: return((int)DialogResult.OK); case MsiInstallMessage.Terminate: return((int)DialogResult.OK); case MsiInstallMessage.User: OnUser(message); return(1); case MsiInstallMessage.Warning: OnWarning(message); return(1); default: break; } } catch (Exception e) { // do something meaningful, but don't re-throw here. OnError("Application error: " + e.ToString(), false); } return(0); }
/// <summary> /// Initializes a new instance of the <see cref="MsiParser" /> class. /// </summary> /// <param name="msiFile">The msi file.</param> public MsiParser(string msiFile) { this.msiFile = msiFile; this.db = MsiParser.Open(msiFile); }