如何禁用 WindowsVista 上的“调试/关闭应用程序”对话框?

当应用程序在 Windows 上崩溃并安装 VisualStudio 等调试器时,将出现以下模式对话框:

[标题: 微软视窗]

X 已经停止工作了

一个问题导致程序停止 正常工作。窗口将关闭 程序,并通知你 解决方案是可行的。

[调试][关闭应用程序]

有没有办法禁用这个对话框? 也就是说,让程序在无声中崩溃和燃烧?

我的场景是,我希望运行几个自动化测试,其中一些测试将由于测试中的应用程序中的错误而崩溃。我不希望这些对话拖延自动化运行。

四处搜索,我想我已经找到了在 Windows XP 上禁用这个功能的解决方案,也就是使用这个 reg 键:

软件 MicrosoftWindowsNT CurrentVersion AeDebug 调试器

但是,这在 WindowsVista 上不起作用。

89154 次浏览

You have to implement an unhandled exception filter which simply quits your application, then set that filter function with SetUnhandledExceptionFilter().

If you're using the secure CRT, you also have to provide your own invalid parameter handler and set this with _set_invalid_parameter_handler().

This blog post has some information too: http://blog.kalmbachnet.de/?postid=75

During test you can run with a 'debugger' like ADPlus attached which can be configured in many useful ways to collect data (minidumps) on errors and yet prevent the modal dialog problems you state above.

If you want to get some useful information when your app crashes in production you can configure Microsoft Error reporting to get something similar to ADPlus data.

To force Windows Error Reporting (WER) to take a crash dump and close the app, instead of prompting you to debug the program, you can set these registry entries:

Windows Registry Editor Version 5.00


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting]
"ForceQueue"=dword:00000001


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\Consent]
"DefaultConsent"=dword:00000001

After this is set, when your apps crash, you should see *.hdmp and *.mdmp files in:

%ALLUSERSPROFILE%\Microsoft\Windows\WER\

I'm not sure if this refers to exactly the same dialog but here is an alternative approach from Raymond Chen:

DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);

See here:

http://msdn.microsoft.com/en-us/library/bb513638.aspx

regedit

DWORD HKLM or HKCU\Software\Microsoft\Windows\Windows Error Reporting\DontShowUI = "1"

will make WER silently report. Then you can set

DWORD HKLM or HKCU\Software\Microsoft\Windows\Windows Error Reporting\Disabled = "1"

to stop it from talking to MS.

After trying everything else on the internet to get rid of just in time debugger, I found a simple way that actually worked and I hope will help someone else.

Go to Control Panel Go to Administrative Tools Go to Services Look down the list for Machine Debug Manager Right Click on it and click on Properties Under the General Tab, look for Start Up Type Click on Disable. Click on Apply and OK.

I haven't seen the debugger message since, and my computer is running perfectly.

I had to disable this for release automation work on Windows 64-bits for Firefox and I did the following:

  • gpedit.msc
  • Computer configuration -> Administrative Templates
  • Windows Components -> Windows Error Reporting
  • Set "Prevent display of the user interface for critical errors" to Enabled

It is similar what was accomplished for Customer Experience reporting in: http://www.blogsdna.com/2137/fix-windows-installer-explorer-update-has-stopped-working-in-windows-7.htm

This isn't a direct answer to the question since this is a workaround and the question is about how to disable that feature, but in my case, I'm a user on a server with limited permissions and cannot disable the feature using one of the other answers. So, I needed a workaround. This will likely work for at least some others who end up on this question.

I used autohotkey portable and created a macro that once a minute checks to see if the popup box exists, and if it does, clicks the button to close the program. In my case, that's sufficient, and leaves the feature on for other users. It requires that I start the script when I run the at-risk program, but it works for my needs.

The script is as follows:

sleep_duration = 60000 ; how often to check, in milliseconds.
; 60000 is a full minute


Loop
{
IfWinExist, ahk_class #32770 ; use autohotkey's window spy to confirm that
; ahk_class #32770 is it for you. This seemed to be consistent
; across all errors like this on Windows Server 2008
{
ControlClick, Button2, ahk_class #32770 ; sends the click.
; Button2 is the control name and then the following
; is that window name again
}
Sleep, sleep_duration ; wait for the time set above
}

edit: A quick flag. When other things are up, this seems to attempt to activate controls in the foreground window - it's supposed to send it to the program in the background. If I find a fix, I'll edit this answer to reflect it, but for now, be cautious about using this and trying to do other work on a machine at the same time.

In my context, I only want to suppress the popup for my unit tests and not for the entire system. I've found that a combination of functions are needed in order to suppress these errors, such as catching unhandled exceptions, suppressing run time checks (such as the validity of the stack pointer) and the error mode flags. This is what I've used with some success:

#include <windows.h>
#include <rtcapi.h>
int exception_handler(LPEXCEPTION_POINTERS p)
{
printf("Exception detected during the unit tests!\n");
exit(1);
}
int runtime_check_handler(int errorType, const char *filename, int linenumber, const char *moduleName, const char *format, ...)
{
printf("Error type %d at %s line %d in %s", errorType, filename, linenumber, moduleName);
exit(1);
}


int main()
{
DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exception_handler);
_RTC_SetErrorFunc(&runtime_check_handler);


// Run your tests here


return 0;
}

In WPF application

[DllImport("kernel32.dll", SetLastError = true)]
static extern int SetErrorMode(int wMode);


[DllImport("kernel32.dll")]
static extern FilterDelegate SetUnhandledExceptionFilter(FilterDelegate lpTopLevelExceptionFilter);
public delegate bool FilterDelegate(Exception ex);


public static void DisableChashReport()
{
FilterDelegate fd = delegate(Exception ex)
{
return true;
};
SetUnhandledExceptionFilter(fd);
SetErrorMode(SetErrorMode(0) | 0x0002 );
}

Instead of changing values in the registry you can completly disable the error reporting on Windows Server 2008 R2, Windows Server 2012 and Windows 8 with: serverWerOptin /disable

https://technet.microsoft.com/en-us/library/hh875648(v=ws.11).aspx