1

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?

Rahul Kishore
  • 380
  • 1
  • 8
  • 19

2 Answers2

1

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.

Rahul Kishore
  • 380
  • 1
  • 8
  • 19
  • 2
    The dialog that you see is from a windows component called "Restart Manager" . The very purpose of Restart Manager is to mitigate system reboot by terminating applications holding up files. The InstallValidate action is responsible for initiating the Restart Manager to kick off. By making use of MSIRESTARTMANAGERCONTROL , you have disabled Restart Manager and hence, windows installer falls back to the legacy "FilesinUse" mechanism. "FilesinUse" has certain drawbacks compared to "Restart Manager" such as not being able to terminate processes which do not have a visible window such – Kiran Hegde Jul 27 '15 at 04:38
  • 2
    as Services. http://www.symantec.com/connect/blogs/files-use-and-restart-manager https://msdn.microsoft.com/en-us/library/windows/desktop/cc948910(v=vs.85).aspx . Just be aware of this fact. As long as you know the drawbacks of not having RestartManager, it is fine. – Kiran Hegde Jul 27 '15 at 04:39
  • Yes @KiranHegde I read about this later on. For right now I am fine, as this application just deals with our own process..it's not a third party process or something that messes around with any of the WIN32 APIs, etc. Thanks for the information. – Rahul Kishore Jul 27 '15 at 04:40
0

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);
    }
A G
  • 21,087
  • 11
  • 87
  • 112
  • Aseem, will this work even if I place this code inside of the OnBeforeUninstall method...I don't think so? None of those events fire before the dialog appears. – Rahul Kishore Jul 26 '15 at 05:11
  • Can't you just put this code in the Uninstall method? – A G Jul 26 '15 at 05:16
  • I placed this in the Uninstall method, still no luck. The Dialog comes before the Uninstall method is fired. Is there no way to suppress to this dialog? – Rahul Kishore Jul 26 '15 at 20:27