如何在 Windows Vista 上禁用“调试/关闭应用程序”对话框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/396369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:53:54  来源:igfitidea点击:

How do I disable the 'Debug / Close Application' dialog on Windows Vista?

windowstestingwindows-vistacrash-reportswindows-error-reporting

提问by Chris Smith

When an application crashes on Windows and a debugger such as Visual Studio is installed the following modal dialog appears:

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

[Title: Microsoft Windows]

X has stopped working

A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.

[Debug][Close Application]

[标题:微软视窗]

X 已停止工作

一个问题导致程序停止正常工作。Windows 将关闭该程序并通知您是否有可用的解决方案。

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

Is there a way to disable this dialog? That is, have the program just crash and burn silently?

有没有办法禁用这个对话框?也就是说,程序是否只是崩溃并默默燃烧?

My scenario is that I would like to run several automated tests, some of which will crash due to bugs in the application under test. I don't want these dialogs stalling the automation run.

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

Searching around I think I've located the solution for disabling this on Windows XP, which is nuking this reg key:

四处搜索,我想我已经找到了在 Windows XP 上禁用此功能的解决方案,该解决方案正在使用此注册表项:

HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

HKLM\Software\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger

However, that did not work on Windows Vista.

但是,这在 Windows Vista 上不起作用。

采纳答案by NicJ

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 错误报告 (WER) 进行故障转储并关闭应用程序,而不是提示您调试程序,您可以设置以下注册表项:

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:

设置后,当您的应用程序崩溃时,您应该在以下位置看到 *.hdmp 和 *.mdmp 文件:

%ALLUSERSPROFILE%\Microsoft\Windows\WER\

回答by NicJ

See here:

看这里:

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

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

regedit

注册表编辑器

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

DWORD HKLM 或 HKCU\Software\Microsoft\Windows\Windows 错误报告\DontShowUI = "1"

will make WER silently report. Then you can set

会让WER默默举报。然后你可以设置

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

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

to stop it from talking to MS.

阻止它与 MS 交谈。

回答by Luke Quinane

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

我不确定这是否指的是完全相同的对话,但这是Raymond Chen的另一种方法:

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

回答by armenzg

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

我必须禁用此功能才能在 Firefox 的 Windows 64 位上进行发布自动化工作,我执行了以下操作:

  • gpedit.msc
  • Computer configuration -> Administrative Templates
  • Windows Components -> Windows Error Reporting
  • Set "Prevent display of the user interface for critical errors" to Enabled
  • gpedit.msc
  • 计算机配置 -> 管理模板
  • Windows 组件 -> Windows 错误报告
  • 将“防止显示严重错误的用户界面”设置为已启用

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

它类似于客户体验报告中的内容:http: //www.blogsdna.com/2137/fix-windows-installer-explorer-update-has-stopped-working-in-windows-7.htm

回答by Gearoid Murphy

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;
}

回答by Francesco Germinara

In WPF application

在 WPF 应用程序中

[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 );
}

回答by Nick

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 portableand 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.

我使用autohotkey 便携式并创建了一个宏,每分钟检查一次弹出框是否存在,如果存在,单击按钮关闭程序。在我的情况下,这就足够了,并为其他用户保留该功能。它要求我在运行有风险的程序时启动脚本,但它可以满足我的需要。

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.

编辑:一个快速的标志。当其他事情发生时,这似乎试图激活前台窗口中的控件 - 它应该将其发送到后台程序。如果我找到了修复程序,我将编辑此答案以反映它,但就目前而言,请谨慎使用它并尝试同时在机器上执行其他工作。

回答by Stefan

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

您必须实现一个未处理的异常过滤器,它只是简单地退出您的应用程序,然后使用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().

如果您使用的是安全 CRT,您还必须提供自己的无效参数处理程序并使用_set_invalid_parameter_handler() 进行设置。

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

这篇博文也有一些信息:http: //blog.kalmbachnet.de/?postid=75

回答by Steve Steiner

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

在测试期间,您可以使用附加“调试器”(如 ADPlus)运行,该调试器可以通过许多有用的方式进行配置,以收集有关错误的数据(小型转储),同时防止出现您上面提到的模态对话框问题。

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

如果您想在应用程序在生产中崩溃时获得一些有用的信息,您可以配置Microsoft 错误报告以获取类似于 ADPlus 数据的内容。

回答by Vicki Mollenauer

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.

从那以后我就没有看到调试器消息,而且我的计算机运行良好。