Vista: WerRegisterFile

Mon, October 2, 2006, 05:52 AM under Windows | Vista
Did you know that on Vista you can add your own files to the reports of WER?

Here are some steps for achieving that.

1. Create a brand new VS2005 WinForms project on Vista and name it "WerRegisterFile". Add a button to the form and in its event handler stick the following:
    private void button1_Click(object sender, EventArgs e)
{
// simulate crash
Environment.FailFast("bye bye");
}
Build and run the project from the file system to observe WER in action
a) First windows checks if there is a solution to the problem (screenshot).
b) Then it asks the end user to confirm that they'd like to send the report (screenshot)
c1) it then (asynchronously) proceeds with sending the data (e.g. Version.txt, minidump.mdmp) to winqual (screenshot). Note: this can be instantaneous and capturing that screenshot required blistering mouse movement

c2) it then informs the user to close the program (screenshot). Note that if the app registers for restart, then you won't see this dialog and instead the application will re-launch itself :-)

Let's enhance the WER process by adding our own file to send to winqual:

2. In the form paste the following pinvoke declarations:
    internal const int WerRegFileTypeOther = 2;
internal const int WER_FILE_ANONYMOUS_DATA = 2;

[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto)]
internal static extern int WerRegisterFile(string pwzFile, int regFileType, int dwFlags);
3. Anywhere in your project (e.g. form_load, form ctor, button_click etc) before the application crashes make the following call:
WerRegisterFile("danielmoth.txt", WerRegFileTypeOther, WER_FILE_ANONYMOUS_DATA);
4. Go to the build directory of your solution (e.g. bin\release) and create a file named "danielmoth.txt"

Now, when you rebuild and then run the exe form the file system, you'll observe the same screenshots /behaviour as above. So how can we inspect that our own file was sent (other than visiting winqual and checking there)? Well, with 'Problem Reports and Solutions' of course!

Find the entry for "WerRegisterFile" (check the date/time to verify that it was just generated). Click on it and you are presented with the following dialog (I've highlighted with the red arrow the evidence that our file was sent):


If you click on the "View a temporary copy of these files" then you get to view a copy of exactly what was sent.

That's all folks :)

Some quick notes:
i) Remember that if you don't have an internet connection, these reports are queued and you can still view them following the steps I outlined before

ii) If you replace step 1 at the top with the alternative crash I described here (steps a & b), then in the last screenshot where it reads "Problem Signature 09" instead of "FatalError" it would say "System.DivideByZeroException"

iii) In addition to crashes and hangs, you can create and submit reports for other events. Surf the relevant APIs by starting here at WerReportCreate and then examine the APIs in the ‘Remarks’ section (and if you create a cool demo with those please drop me a line!).
Tuesday, 02 December 2008 23:18:00 (Pacific Standard Time, UTC-08:00)
FYI, I have tested this code in Windows 64bit and Environment.FailFast("Bye"); does not show the Send Information dialog when the WER dialogs appear. However if I crash the application using ThreadHijacker then all works as expected and the dumps and additional files are sent.
Wednesday, 03 December 2008 14:49:03 (Pacific Standard Time, UTC-08:00)
Luke: Thanks for your message (I also saw your other one pointing to the code here). When I wrote the code >2 years ago obviously it worked, but that was not on 64bit, so I am not sure if the problem is related to that. Try downloading the full project from my Vista demos post and see if it repros.
Comments are closed.