对一个Windows应用程序处理结束进程应用程序、进程、结束、Windows

2023-09-02 10:26:27 作者:言不由衷

是否有可能捕捉到相同的Windows应用程序本身的一个Windows应用程序的任务管理器结束进程?我使用的是C#2.0的胜利应用程序,我想做些数据库处理(在数据库中更改国旗'Y',以'N')时结束的过程发生。

Is it possible to capture the task manager end process of a windows application within the same windows application itself? I am using a C# 2.0 win app and I would like to do some database processing (change a flag from 'Y' to 'N' in the DB) when an end process happens.

推荐答案

没有,那是不可能的勾操作系统的决定,结束进程。注意,这不是由任务管理器完成,结束了处理是内核的责任。

No, it is not possible to hook the operating system's decision to end a process. Note, this is not done by task manger, ending a process is the responsibility of the kernel.

您需要做两件事情:

连接事件处理程序来告诉一个应用程序退出普通用户界面消息。使用这些事件中留存数据,免费的资源,并以其他方式退出的。 在处理异常适当捕获错误和清理,如果可能保存数据。

下面是三个环节,以林峰的博客解释为什么你不能做什么你问。

Here are a three links to Raymond's blog explaining why you cannot do what you are asking.

你为什么不能捕获TerminateProcess? 为什么有些工艺停留在任务管理器,他们已经被杀害后? 程序和用户之间的军备竞赛 Why can't you trap TerminateProcess? Why do some process stay in Task Manager after they've been killed? The arms race between programs and users

另外,我处理了类似的StackOverflow问题here.

Also, I addressed a similar StackOverflow question here.