1
votes

I have a C# application. All works fine except this:

When I uninstall the application from add/remove programs, if app is not closed it will remain open after uninstall.

For guys that can't read an implied question... "How do I make it so the application will close? at uninstall?".

If you need any details just ask.

3
Maybe, before we ask something, you should do so. You are missing a question! - Daniel Hilgarth
Can you properly uninstall an app if it still running? I don't think the .exe is deleted. - Gabriel
It is deleted. The only problem is that it remains in ram somewhere. Can't I make a listener of some kind? When X opens add/rem prg to close it? - zozo

3 Answers

3
votes

In your Installer project (I'm assuming you have generated an MSI installer using an Installer project in Visual Studio), you should include a class that inherits from the Installer base class:

[RunInstaller(true)]
public class MyInstaller: Installer
{
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
    }


    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);

        //TODO: Code to kill the live instance(s)
    }

    // Other override methods here if necessary
}

This class' Uninstall method will get executed when the user uninstalls your application.

In this method, you can select the list of running processes and kill all live instances of your app.

0
votes

Maybe it is open because it is in ram memory. Just close it.

0
votes

This is just how it works.

Uninstall removes it from disk, not from memory.

You would have to add some custom code to the uninstall operation to get the app to close before uninstall