简体   繁体   English

运行 windows 卸载程序时关闭应用程序

[英]Close application when running windows uninstaller

I have a C# application.我有一个 C# 应用程序。 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.如果您需要任何详细信息,请询问。

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:在您的安装程序项目中(我假设您已经使用 Visual Studio 中的安装程序项目生成了一个 MSI 安装程序),您应该包含一个继承自安装程序基础 class 的 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.当用户卸载您的应用程序时,将执行此类的 Uninstall 方法。

In this method, you can select the list of running processes and kill all live instances of your app.在这种方法中,您可以 select 正在运行的进程列表并杀死您的应用程序的所有活动实例。

Maybe it is open because it is in ram memory.也许它是打开的,因为它在 ram memory 中。 Just close it.关闭它。

This is just how it works.这就是它的工作原理。

Uninstall removes it from disk, not from memory.卸载会将其从磁盘中删除,而不是从 memory 中删除。

You would have to add some custom code to the uninstall operation to get the app to close before uninstall您必须在卸载操作中添加一些自定义代码才能在卸载之前关闭应用程序

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

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