A summary from the answers by jdehaan and Eric Brown, as well as this question:
Option 1:
Works globally on the entire user account or machine, which can be both a benefit and a drawback.
Set [HKLM|HKCU]\Software\Microsoft\Windows\Windows Error Reporting\DontShowUI
to 1.
More info: WER settings.
Option 2:
Requires modification to the crashing program.
Call SetErrorMode: SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
. More info: Disabling the program crash dialog (explains the odd arrangement of calls).
Option 3:
Requires modification to the crashing program.
Use SetUnhandledExceptionFilter
to set your own structured exception handler that simply exits.
Option 4:
Requires modification to the crashing program. For .NET applications only.
Wrap all code into a global try/catch block. Specify the HandleProcessCorruptedStateExceptionsAttribute
and possibly also the SecurityCriticalAttribute
on the method catching the exceptions. More info: Handling corrupted state exceptions
Option 5:
Works globally on the entire user account, but only for a controlled duration.
Kill the Windows Error Reporting process whenever it shows up:
var werKiller = new Thread(() =>
{
while (true)
{
foreach (var proc in Process.GetProcessesByName("WerFault"))
proc.Kill();
Thread.Sleep(3000);
}
});
werKiller.IsBackground = true;
werKiller.Start();
This is not completely bullet-proof though, because a console application may crash via a different error message, apparently displayed by an internal function called NtRaiseHardError
: