Disable debug prompt on application crash

2020-02-04 20:36发布

问题:

Question: I need to disable the console application's crash debug prompt.

Background: We've got an application that syncs info with a third party that crashes due to connectivity problems with the 3rd party at certain times of the day. We don't have access to the source code to trap the error properly so I just need the application to fail and try again. I've got another application that monitors our sync tool to make sure it's running.

when the sync apps crashes there is a debug prompt that requires a users interaction. Because this stays on the screen the application never actually stops running. As a result the "health check" never knows of the failure.

I've done this about 2 years ago but for the life of me I can't the remember the article or the needed registry path.

Thanks, Brian

OS: Windows 2003 Server Application Type: .NET 3.5 Console Application


FIX: found by: John Knoeller

Delete the following keys

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ .NETFramework\DbgManagedDebugger

回答1:

Possibly this?

How to: Enable/Disable Just-In-Time Debugging

The registry keys are

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger 


回答2:

Deleting entire keys seems too "hammer" approach.

First, one can use Windows API functions SetErrorMode and/or SetThreadErrorMode. They can be PInvoked from .NET application too.

The related signatures for PInvoke are:

    public enum ErrorMode : uint
    {
        SEM_DEFAULT                 = 0x0000,
        SEM_FAILCRITICALERRORS      = 0x0001,
        SEM_NOGPFAULTERRORBOX       = 0x0002,
        SEM_NOALIGNMENTFAULTEXCEPT  = 0x0004,
        SEM_NOOPENFILEERRORBOX      = 0x8000
    }

    [DllImport("Kernel32.dll")]
    public static extern ErrorMode SetErrorMode(ErrorMode mode);  //available since XP

    [DllImport("Kernel32.dll")]
    public static extern ErrorMode GetErrorMode();  //available since Vista

    [DllImport("kernel32.dll", SetLastError = true)]
    public static extern bool SetThreadErrorMode(ErrorMode newMode, out ErrorMode oldMode);    //available since Windows 7

    [DllImport("Kernel32.dll")]
    public static extern ErrorMode GetThreadErrorMode();    //available since Windows 7


Secondly, there is a more specific registry-based solution since Vista:
Excluding only this application from being debugged. See this:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb204634(v=vs.85).aspx

Copy-paste:

Excluding an Application from Automatic Debugging

The following procedure describes how to exclude an application from automatic debugging after the Auto value under the AeDebug key has been set to 1.

--> To exclude an application from automatic debugging go to the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug
Add a REG_DWORD value to the AutoExclusionList subkey, where the name is the name of the executable file and the value is 1.
By default, the Desktop Window Manager (Dwm.exe) is excluded from automatic debugging because otherwise a system deadlock can occur if Dwm.exe stops responding (the user cannot see the interface displayed by the debugger because Dwm.exe isn't responding, and Dwm.exe cannot terminate because it is held by the debugger).
Windows Server 2003 and Windows XP: The AutoExclusionList subkey is not available; thus you cannot exclude any application, including Dwm.exe, from automatic debugging.

The default AeDebug registry entries can be represented as follows:
HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows NT CurrentVersion AeDebug Auto = 1 AutoExclusionList DWM.exe = 1



回答3:

John's solution as a .reg file (we needed to roll this out to a cluster of build servers):

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Debugger"=-

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"DbgManagedDebugger"=-