1+ param (
2+ [Parameter (Mandatory = $true )][string ]$Exe ,
3+ [string ]$cdb = " C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\cdb.exe"
4+ )
5+
6+ $scriptDir = Split-Path - Parent $PSCommandPath
7+
8+ if (-not (Test-Path $Exe )) {
9+ Write-Host " Error: File $Exe does not exist!" - ForegroundColor Red
10+ exit -2
11+ }
12+ if (-not (Test-Path $cdb )) {
13+ Write-Host " Error: cdb not found at $cdb " - ForegroundColor Red
14+ exit -2
15+ }
16+
17+ $p = Start-Process - FilePath $Exe - NoNewWindow - Wait - PassThru
18+ $exitCode = $p.ExitCode
19+
20+ if ($exitCode -eq 0 ) {
21+ Write-Host " Application exited with code 0 (success)" - ForegroundColor Green
22+ exit 0
23+ }
24+
25+ Write-Host " Application exited with code $exitCode (crash)" - ForegroundColor Red
26+ Write-Host " Re-running with CDB attached!" - ForegroundColor Cyan
27+
28+ $dumpFile = " $env: TEMP \$name .dmp"
29+
30+ if (Test-Path $dumpFile ) {
31+ Remove-Item $dumpFile - Force
32+ }
33+
34+ & $cdb - lines - y srv* - c " sxn ld; g; !analyze -v; lm v; kp; .dump /ma $dumpFile ; q" $Exe | Out-Host
35+ Write-Host " Process execution completed" - ForegroundColor Yellow
36+
37+ $exeName = [IO.Path ]::GetFileName($Exe )
38+ $werPaths = @ (
39+ " $env: PROGRAMDATA \Microsoft\Windows\WER" ,
40+ " $env: LOCALAPPDATA \Microsoft\Windows\WER"
41+ )
42+
43+ $lastWer = Get-ChildItem $werPaths - Recurse - Filter Report.wer - ErrorAction SilentlyContinue |
44+ Sort-Object LastWriteTime - Descending |
45+ Where-Object { Select-String - Path $_.FullName - SimpleMatch $exeName - Quiet } |
46+ Select-Object - First 1
47+
48+ if ($lastWer ) {
49+ Write-Host " WER report for ${exeName} :" - ForegroundColor Cyan
50+ Get-Content $lastWer.FullName | Out-Host
51+ } else {
52+ Write-Host " Could not find last WER report for $exeName " - ForegroundColor DarkYellow
53+ }
54+
55+ exit -1
0 commit comments