Make CrashDumps dump into same folder that app runs from

后端 未结 1 1710
臣服心动
臣服心动 2021-01-27 17:35

I\'ve written an application that I want to have some level of automatic debugging for. I want to use windows error reporting to output the crash dump into the same folder that

1条回答
  •  伪装坚强ぢ
    2021-01-27 18:11

    I had a similar requirement on a previous project. I wanted to trap the crash dump file that WER produces. That is, I did not want it to be sent to the WER reporting server. That required me to set the LocalDumps WER registry key and some values. I wrote a small utility program that uses the following code snippet. Note, I had to run this code as admin.

    CRegKey rk;
    TCHAR pszValue[MAX_PATH+1] = {0};
    DWORD dwValue = 0;
    DWORD dwSize = MAX_PATH;
    
    //  check for existence of "LocalDumps" key.
    LONG ret = rk.Open (HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\Windows Error Reporting"),
            KEY_WRITE | KEY_WOW64_64KEY);
    if (ret == ERROR_SUCCESS)
        {
        ret = rk.Create (rk.m_hKey, _T("LocalDumps\\.exe"));
        if (ret == ERROR_SUCCESS)
            {
            CString szText;
            DWORD dwValue = 0;
    
            m_NumDumpsED.GetWindowText (szText);
            dwValue = atol (szText);
            rk.SetDWORDValue (_T("DumpCount"), dwValue);
            m_DumpFolderED.GetWindowText (szText);
            rk.SetStringValue (_T("DumpFolder"), szText);
            dwValue = (m_MiniFullRB == 0) ? 1 : 2;
            rk.SetDWORDValue (_T("DumpType"), dwValue);
            }
        else
            AfxMessageBox (_T("Error creating 'LocalDumps\\.exe' key"), MB_OK);
        }
    

    In order to trap the dump file, you must create a child sub-key for LocalDumps that is the name of your application. That part may not be obvious in the WER documentation. As long as that key exists, WER will trap the dump. You then set the DumpCount, DumpFolder, and DumpType values to meet your needs. For more info on these values, you can consult the WER registry settings help.

    0 讨论(0)
提交回复
热议问题