问题
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 the app is running from. My idea here is that I can then have my application look in it's own folder for any dmp files and then upload them for analysis if needed.
I've got the appropriate registry keys for everything else but how do I set up the DumpFolder key to point back to whatever location my app is ran from?
回答1:
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\\<your application>.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\\<your application>.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.
来源:https://stackoverflow.com/questions/27848126/make-crashdumps-dump-into-same-folder-that-app-runs-from