简体   繁体   English

CustomAction中的终止过程

[英]Terminating process in CustomAction

I have a custom action installer class where I am trapping both of the following events: 我有一个自定义操作安装程序类,在其中捕获了以下两个事件:

  1. OnBeforeUninstall OnBeforeUninstall
  2. Uninstall 卸载

What I'm actually trying to do is, terminate a process that I've created in my main application...this "process" is essentially an exe I've started that sits in the System Tray and displays notifications to users every 2 minutes. 我实际上想做的是终止在主应用程序中创建的进程...此“进程”本质上是我启动的一个exe,它位于系统托盘中,每隔2个向用户显示通知分钟。

When I choose to uninstall my main application I'm prompted with the following dialog: 当我选择卸载主应用程序时,系统将提示以下对话框:

在此处输入图片说明

However, it's strange that the code I've put in OnBeforeUninstall and Uninstall get fired after this dialog. 但是,奇怪的是, 此对话框之后,我在OnBeforeUninstall和Uninstall中输入的代码被触发了。

I don't want this dialog to show up at all. 我根本不想显示此对话框。

Am I doing something wrong? 难道我做错了什么?

From my research, I've noticed that this dialog is from the InstallValidate key in ORCA. 从我的研究中,我注意到此对话框来自ORCA中的InstallValidate键。 I do not know if it is safe to schedule my CA before this. 我不知道在此之前安排我的CA是否安全。

Any way to safely terminate my process without having this dialog appear? 有什么办法可以安全地终止我的进程而不会出现此对话框?

Well, after a lot of research on Google and on a particular Yahoo forum, all I needed to do was edit the MSI via Orca. 好吧,在Google和特定Yahoo论坛上进行了大量研究之后,我要做的就是通过Orca编辑MSI。

  1. Opened the Property table 打开属性表
  2. Added the MSIRESTARTMANAGERCONTROL property 添加了MSIRESTARTMANAGERCONTROL属性
  3. Set it's value to Disable 将其值设置为“ 禁用”

Got rid of the Dialog appearing, and my own custom action code took care of killing the process. 摆脱了对话框的出现,我自己的自定义操作代码负责终止该过程。

Hope this helps someone. 希望这对某人有帮助。

You need to wait for the process to exit and then proceed with the uninstallation - WaitForExit or HasExited 您需要等待进程退出,然后继续卸载-WaitForExitHasExited

The Kill method executes asynchronously. Kill方法异步执行。 After calling the Kill method, call the WaitForExit method to wait for the process to exit, or check the HasExited property to determine if the process has exited. 调用Kill方法之后,请调用WaitForExit方法以等待进程退出,或者检查HasExited属性以确定进程是否退出。

Process p = ...
p.Kill();
while(!p.HasExited)
{ 
    p.WaitForExit(1000); 
}

Kill process before the uninstall begins - 在卸载开始之前终止进程-

public override void Uninstall(System.Collections.IDictionary savedState)
    {
        KillProcess();
        base.Uninstall(savedState);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM