简体   繁体   English

如何以编程方式检测Windows中已崩溃的应用程序?

[英]How to programmatically detect an application has crashed in Windows?

I am running a Python script that launches a number of apps. 我正在运行一个Python脚本,该脚本可以启动许多应用程序。 I need a way to detect if the app that's launched has crashed. 我需要一种方法来检测启动的应用程序是否崩溃。 Some apps have internal crash handling 一些应用具有内部崩溃处理

该应用程序已崩溃,并有一个对话框显示该应用程序已崩溃

How can I detect the crash? 如何检测崩溃?

If they have internal crash handling, it's not possible to detect. 如果他们具有内部崩溃处理,将无法检测到。 The application will handle the error and exit normally. 该应用程序将处理该错误并正常退出。 You can't even detect this if you would attach yourself as a debugger. 如果您将自己附加为调试器,您甚至都无法检测到。

The reason is exception dispatching (MSDN) : 原因是异常调度(MSDN)

  1. the debugger gets informed about an exception. 调试器会收到有关异常的通知。 This is called the first chance exception. 这称为第一次机会异常。 However, this might be "normal", eg FileNotFound, which is expected by the application. 但是,这可能是“正常”的,例如FileNotFound,这是应用程序所期望的。
  2. Windows is looking for someone who wants to handle the exception. Windows正在寻找想要处理该异常的人。 This can be the except block of a Python application, a catch block in C# or C++ or even a general "unhandled exception handler". 这可以是Python应用程序的except块,C#或C ++中的catch块,甚至是常规的“未处理的异常处理程序”。
  3. If nobody wanted to handle the application, the debugger gets informed again. 如果没有人希望处理该应用程序,则调试器将再次得到通知。 This time, the exception is marked as a second chance exception. 这次,该异常被标记为第二次机会异常。 This means that the application will crash next. 这意味着应用程序接下来将崩溃。

You're looking to become informed as part of step 3, however, the application has already stopped the process in step 2. 您希望作为第3步的一部分得到通知,但是,该应用程序已在第2步中停止了该过程。

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

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