11@ echo off
2- REM SetupLocalDumps.cmd [ExecutableName] [DumpFolder]
3- REM Ex: .\SetupLocalDumps.cmd RNTesterApp C:\WER\UserDumps
2+ REM SetupLocalDumps.cmd [ExecutableName] [DumpFolder] [DumpType] [DumpCount]
3+ REM Ex: .\SetupLocalDumps.cmd RNTesterApp-Fabric C:\WER\UserDumps
4+ REM Ex: .\SetupLocalDumps.cmd RNTesterApp-Fabric C:\WER\UserDumps 2 5
45REM
5- REM This script sets the registry so that, if an executable of the given name crashes, to
6- REM prevent any automatic debugger from attaching, and instead save a full crash dump to
7- REM the given folder.
6+ REM Configures Windows Error Reporting (WER) to save crash dumps for the named
7+ REM executable to the given folder. This is the supported mechanism for
8+ REM packaged/UWP apps where AeDebug-based JIT debuggers (e.g. ProcDump) are
9+ REM not reliably invoked.
10+ REM
11+ REM DumpType:
12+ REM 1 = Custom dump (uses CustomDumpFlags)
13+ REM 2 = Full dump (default)
14+ REM 3 = Mini dump
15+ REM
16+ REM DumpCount: max number of dumps to keep per exe (default 10)
817
9- setlocal
18+ setlocal enableextensions
1019
11- if " %1 " == " " (
20+ if " %~ 1 " == " " (
1221 @ echo Must provide an executable name to set up local crash dumps
1322 exit /b 1
1423)
15- if " %2 " == " " (
24+ if " %~ 2 " == " " (
1625 @ echo Must provide a writable folder to save local crash dumps
1726 exit /b 1
1827)
1928
20- set CRASHDUMPS_FOLDER = %2
21- @ echo Configuring registry to save " %1 .exe" crash dumps to " %CRASHDUMPS_FOLDER% " ...
22- reg add " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\%1 .exe" /v DumpFolder /t REG_EXPAND_SZ /d %CRASHDUMPS_FOLDER%
23- reg add " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\%1 .exe" /v DumpType /t REG_DWORD /d 2
24- reg add " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\%1 .exe" /v DumpCount /t REG_DWORD /d 3
25- reg add " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList" /v %1 .exe /t REG_DWORD /d 1
26- if not exist %CRASHDUMPS_FOLDER% (
29+ set EXE_NAME = %~1
30+ set CRASHDUMPS_FOLDER = %~2
31+ set DUMP_TYPE = %~3
32+ set DUMP_COUNT = %~4
33+ if " %DUMP_TYPE% " == " " set DUMP_TYPE = 2
34+ if " %DUMP_COUNT% " == " " set DUMP_COUNT = 10
35+
36+ if not exist " %CRASHDUMPS_FOLDER% " (
2737 @ echo Creating %CRASHDUMPS_FOLDER%
28- md %CRASHDUMPS_FOLDER%
38+ md " %CRASHDUMPS_FOLDER% "
2939)
3040
41+ set REG_KEY = HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\%EXE_NAME% .exe
42+ @ echo Configuring WER to save " %EXE_NAME% .exe" crash dumps (DumpType=%DUMP_TYPE% , DumpCount=%DUMP_COUNT% ) to " %CRASHDUMPS_FOLDER% " ...
43+ reg add " %REG_KEY% " /v DumpFolder /t REG_EXPAND_SZ /d " %CRASHDUMPS_FOLDER% " /f
44+ reg add " %REG_KEY% " /v DumpType /t REG_DWORD /d %DUMP_TYPE% /f
45+ reg add " %REG_KEY% " /v DumpCount /t REG_DWORD /d %DUMP_COUNT% /f
46+
47+ REM Prevent the AeDebug post-mortem debugger from being invoked for this
48+ REM executable so that WER LocalDumps gets first crack and writes to our folder.
49+ reg add " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList" /v %EXE_NAME% .exe /t REG_DWORD /d 1 /f
50+
3151@ echo Registry configuration:
32- reg query " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\ %1 .exe " /s
33- reg query " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList"
52+ reg query " %REG_KEY% " /s
53+ reg query " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList" /v %EXE_NAME% .exe
3454
3555endlocal
3656
37- exit /b %ERRORLEVEL%
57+ exit /b %ERRORLEVEL%
0 commit comments