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