How to Disable “This Program Has Stopped Working” Dialog in Windows Server 2008 for Automated CLI Processes


2 views

When running command-line programs in automated workflows on Windows Server 2008, the system often interrupts the process with the infamous "This program has stopped working" dialog. This becomes particularly problematic in:

  • Scheduled tasks running overnight
  • CI/CD pipelines
  • Batch processing jobs
  • Remote execution scenarios

While many administrators first try disabling error reporting through the Control Panel or Group Policy, these approaches often don't resolve the issue because:

\\ Traditional approaches that don't work:
1. Control Panel → System → Advanced → Error Reporting → "Disable error reporting"
2. gpedit.msc → Computer Config → Admin Templates → Windows Components → Windows Error Reporting

The most effective method involves modifying the Windows registry to suppress these dialogs system-wide:

Windows Registry Editor Version 5.00

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

[HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting]
"DontShowUI"=dword:00000001

Save this as disable_wer.reg and run as Administrator. For immediate effect without reboot:

taskkill /f /im werfault.exe

For more granular control when you need to keep error reporting active for other applications, use the WerAddExcludedApplication API:

#include <windows.h>
#include <werapi.h>

int main() {
    WerAddExcludedApplication(L"your_cli_app.exe", FALSE);
    return 0;
}

Or via PowerShell for quick implementation:

Add-Type @"
using System;
using System.Runtime.InteropServices;

public class WER {
    [DllImport("wer.dll", CharSet=CharSet.Unicode)]
    public static extern int WerAddExcludedApplication(string pwzExeName, bool bAllUsers);
}
"@

[WER]::WerAddExcludedApplication("your_cli_app.exe", $true)

For scenarios where you still want crash notifications but need automated handling:

:: Batch script example with error handling
:retry
your_cli_app.exe || (
    timeout /t 5
    taskkill /im your_cli_app.exe /f
    goto retry
)

After implementation, verify the changes by:

  1. Creating a test crash program:
  2. int main() { *(int*)0 = 0; return 0; }  // Guaranteed crash
  3. Running through Task Scheduler
  4. Checking Event Viewer (Application logs) for silent failures

When running command-line programs in automated workflows on Windows Server 2008, the "This program has stopped working" dialog can become a significant roadblock. This modal dialog requires manual interaction (clicking "Close"), which completely defeats the purpose of automation. I've encountered this issue numerous times while managing batch processing systems, and standard approaches like disabling Windows Error Reporting often prove ineffective.

The dialog appears when Windows detects an application crash through its Windows Error Reporting (WER) system. Even with error reporting disabled, the system still shows the basic crash notification dialog. This behavior stems from how Windows handles unhandled exceptions in applications.

The most reliable method involves modifying the Windows Registry to completely suppress these dialogs:

Windows Registry Editor Version 5.00

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

[HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting]
"Disabled"=dword:00000001
"DontShowUI"=dword:00000001

For immediate effect, execute this PowerShell command after making registry changes:

Stop-Service -Name WerSvc -Force
Set-Service -Name WerSvc -StartupType Disabled

For enterprise environments, Group Policy offers a more manageable solution:

  1. Open gpedit.msc
  2. Navigate to: Computer Configuration → Administrative Templates → Windows Components → Windows Error Reporting
  3. Enable "Prevent display of the user interface for critical errors"
  4. Set "Configure Error Reporting" to Disabled

For programs you control, adding proper exception handling is ideal. Here's a C++ example for console applications:

#include <windows.h>
#include <excpt.h>

int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep) {
    return EXCEPTION_EXECUTE_HANDLER;
}

int main() {
    __try {
        // Your main program logic here
    }
    __except(filter(GetExceptionCode(), GetExceptionInformation())) {
        // Silent exit on crash
        ExitProcess(1);
    }
    return 0;
}

After implementing these changes, test with a program that intentionally crashes. The crash should now result in silent termination without any UI interruption.