Rahul Kishore
Rahul Kishore

Reputation: 380

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:

enter image description here

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?

Upvotes: 1

Views: 1035

Answers (2)

Rahul Kishore
Rahul Kishore

Reputation: 380

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.

Upvotes: 1

A G
A G

Reputation: 22597

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

Upvotes: 0

Related Questions