How To Change Hard Error Popup Handling in Windows NT

ID: Q128642

3.50 3.51 4.00 WINDOWS NT

  kbhowto

The information in this article applies to:

SUMMARY

In an unattended environment, you may want to automatically dispatch hard error popups that require user intervention. This article gives you the code you need to change the hard error popup mode.

MORE INFORMATION

Windows NT allows the user to change the handling of hard error popups that result from application and system errors. Such errors include no disk in the drive and general protection (GP) faults.

Normally, these events cause a hard error popup to be displayed, which requires user intervention to dispatch. This behavior can be modified so that such errors are logged to the Windows NT event log. When the error is logged to the event log, no user intervention is necessary, and the system provides a default handler for the hard error. The user can examine the event log to determine the cause of the hard error.

Registry Entry

The following registry entry controls the hard error popup handling in Windows NT:

   HKEY_LOCAL_MACHINE\ 
    SYSTEM\ 
    CurrentControlSet\ 
    Control\ 
    Windows\ 
    ErrorMode

Valid Modes

The following are valid values for ErrorMode:

In all modes, system-originated hard errors are logged to the system log. To run an unattended server, use mode 2.

Sample Code to Change Hard Error Popup Mode

The following function changes the hard error popup mode. If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE.

BOOL SetGlobalErrorMode(

    DWORD dwErrorMode   // specifies new ErrorMode value
    )
{
    HKEY hKey;
    LONG lRetCode;

    // make sure the value passed isn't out-of-bounds
    if (dwErrorMode > 2) return FALSE;

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                    "SYSTEM\\CurrentControlSet\\Control\\Windows",
                    0,
                    KEY_SET_VALUE,
                    &hKey) != ERROR_SUCCESS) return FALSE;

    lRetCode=RegSetValueEx(hKey,
                            "ErrorMode",
                            0,
                            REG_DWORD,
                            (CONST BYTE *) &dwErrorMode,
                            sizeof(DWORD) );

    RegCloseKey(hKey);

    if (lRetCode != ERROR_SUCCESS) return FALSE;

    return TRUE;
}

Sample Code to Obtain Hard Error Popup Mode

The following function obtains the hard error popup mode. If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. If the function succeeds, dwErrorMode contains the error popup mode. Otherwise, dwErrorMode is undefined.

BOOL GetGlobalErrorMode(

    LPDWORD dwErrorMode // Pointer to a DWORD to place popup mode
    )
{
    HKEY hKey;
    LONG lRetCode;
    DWORD cbData=sizeof(DWORD);

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                    "SYSTEM\\CurrentControlSet\\Control\\Windows",
                    0,
                    KEY_QUERY_VALUE,
                    &hKey) != ERROR_SUCCESS) return FALSE;

    lRetCode=RegQueryValueEx(hKey,
                            "ErrorMode",
                            0,
                            NULL,
                            (LPBYTE) dwErrorMode,
                            &cbData );

    RegCloseKey(hKey);

    if (lRetCode != ERROR_SUCCESS) return FALSE;

    return TRUE;
}

KBCategory:   kbhowto
KBSubcategory: BseErrdebug BseMisc CodeSam Additional reference words: 3.50 4.00
Keywords          : kbcode kberrmsg kbnokeyword kbKernBase CodeSam kbGrpKernBase 
Version           : 3.50 3.51 4.00
Platform          : NT WINDOWS

Last Reviewed: May 23, 1998