微星如何检测是Excel运行

我们的应用程序是Excel加载项。 我们使用Wix 3.10来构buildMSI。 目前我们可以执行卸载的应用程序,即使Excel运行连接加载项。 如果Excel正在运行,我需要中断卸载过程。 我们不需要closuresExcel,我只需要检测它是否正在运行。 如果是这样,我需要向用户显示适当的消息,并停止卸​​载过程。 如何检测在卸载过程中运行的Excel(任何应用程序)? 我可以使用“标准”MSI / Wixfunction实现所需的行为,还是应该编写一些自定义操作?

如果excel进程正在运行,您将需要一个自定义操作来查询Windows,并设置一个属性和结果。 然后你可以在Launch Condition(Condition元素)中使用它来通知用户和块安装。

最后我实现了我自己的自定义操作。 此操作会触发任何安装模式:安装/卸载/修复等操作显示消息框,要求用户closuresExcel并有两个button“重试”和“取消”。 如果用户按“重试”代码重复检查是Excel运行,“取消”导致另一个对话框,当用户被要求继续或真正取消。 在C#中有动作(请注意,这个代码是使用Wix SDK: Microsoft.Deployment.WindowsInstaller.dll ):

 [CustomAction] public static ActionResult IsExcelRunning(Session session) { session.Log("Begin IsExcelRunning."); MessageResult msgBoxResult = MessageResult.Cancel; do { session.Log("Try to find running Excel."); bool isExcelRunning = false; try { var obj = Marshal.GetActiveObject("Excel.Application"); isExcelRunning = null != obj; session.Log("IsExcelRunning = " + isExcelRunning); if (null != obj) { Marshal.FinalReleaseComObject(obj); obj = null; GC.Collect(); } } catch (Exception ex) { session.Log("Exception:" + ex); } if (!isExcelRunning) { session.Log("End IsExcelRunning."); return ActionResult.Success; } else { var errorRecord = new Record(1); errorRecord.SetInteger(1, 30000); try { msgBoxResult = session.Message(InstallMessage.Error | (InstallMessage) MessageButtons.RetryCancel, errorRecord); } catch (InstallCanceledException) { var questionRecord = new Record(1); questionRecord.SetInteger(1, 1602); if (MessageResult.Yes == session.Message( InstallMessage.Error | (InstallMessage)MessageButtons.YesNo | (InstallMessage)MessageBoxIcon.Question, questionRecord)) { session.Log("End SetIsExcelRunning."); return ActionResult.UserExit; } else { msgBoxResult = MessageResult.Retry; } } catch (Exception ex) { session.Log("Unexpected exception:" + ex); throw; } } } while (MessageResult.Retry == msgBoxResult); session.Log("End IsExcelRunning."); return ActionResult.UserExit; }