简体   繁体   中英

Terminating process in CustomAction

I have a custom action installer class where I am trapping both of the following events:

  1. 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.

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.

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. I do not know if it is safe to schedule my CA before this.

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.

  1. Opened the Property table
  2. Added the MSIRESTARTMANAGERCONTROL property
  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

The Kill method executes asynchronously. 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.

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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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