Windows 安装程序如何在卸载期间关闭应用程序?

How does Windows Installer close an application during uninstall?

卸载我的应用程序时,如果它是 运行:

,它会尝试停止它

遗憾的是,自动关闭并没有真正起作用,它显示了这个错误:

我的应用程序消失了,windows,托盘栏图标,它们都消失了。但是我仍然可以在进程列表中看到它们。

我猜 Windows 向应用程序发送信号以正常退出并且 UI 这样做了,但是有一些延迟线程阻止进程终止。

Windows 安装程序如何在卸载过程中关闭应用程序?

一旦我知道这一点,我想在调试我的应用程序时模拟它以查看发生了什么。这是一个合理的计划吗?

自 Windows Vista 起,Windows 安装程序将利用 Restart Manager to identify, close, and restart applications. Microsoft's documentation on Using Restart Manager, and in particular Using Restart Manager with a Primary Installer should be a solid starting point for implementing a test harness. Your applications and services should instead follow the Guidelines for Applications and Services

如果可能,Guidelines for Applications discuss the messages sent to your application by the restart manager; services are restarted through the service control manager. In theory you could simulate the restart manager at that level, but I suspect you'd be better served by invoking the real thing, registering a carefully chosen list of resources 仅针对您的应用程序。