简体   繁体   中英

How can I automatically catch and restart a crashed process on Windows?

This might be silly. When my process crashes, a WerFault.exe has been launched and I can regain control only after I close this window or kill its task.

I'm looking for a simple way of not letting crashed program show this window or any idea for me to catch this crash.

SEH is not useful, by the way. I'm not sure why. The crash also remains when I use SEH.

Thanks!

Now I'm just figuring out how to avoid this WerFault.exe windows and sometimes csrss.exe window and regain control.

Use the Application Recovery and Restart API to have Windows Error Reporting (WER) restart and recover your app when it crashes. Use RegisterApplicationRestart() to register your intent to be restarted. Use RegisterApplicationRecoveryCallback() to register your intent to save and recover state data.

I have not tried this but this api : WerAddExcludedApplication should disable error raporting: http://msdn.microsoft.com/en-us/library/bb513617%28v=VS.85%29.aspx

As for restarting your app, you could create another background process that will start your main process and monitor how it behaves. If it crashes then restart it.

[edit]

unfortunately this api might not work, as suggested in comments to it - to remove this dialog your will have to FindWindow() and SendMessage(... WM_CLOSE...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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