Make CrashDumps dump into same folder that app runs from
Asked Answered
N

1

0

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?

Napalm answered 8/1, 2015 at 19:32 Comment(2)
Do you have a WER account, or, are you trying to "roll your own" crash reporting?Pharyngitis
I don't have a WER account. I've generated the pdb and plan on debugging crashdumps with WinDBG as I do on my development system. I'm just trying to get a way for my customers to have a standardized way of generating these dump files to send to me.Napalm
P
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.

Pharyngitis answered 9/1, 2015 at 14:7 Comment(3)
This is essentially what I had in mind, except I was just going to import a .reg as part of the application install process. My question, though, is about how to set that DumpFolder to be the folder in which my application is installed. If the user decides to install my application to another drive or something like that, I want the dumps in a CrashDumps folder in my application folder.Napalm
I was thinking about just hard coding it to C:\RubixApp\CrashDumps, but then realized that the user could just as easily install the app to D:\RubixApp\ and then I'd need the dumps moved there. Ideally, I'd like WER to just put the crashdump in a folder called CrashDumps\ in the same path as the crashing exe.Napalm
If you want the location of where your app is installed, you'll need to use something like GetModuleFileName. I'm not sure that will fit into your scenario of updating using a .reg file. You may need to consider adding code to the start up of your app.Pharyngitis

© 2022 - 2024 — McMap. All rights reserved.