Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created December 30, 2020 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/5611fd6972a4dfe3b1a01808c09bbfb2 to your computer and use it in GitHub Desktop.
Save bill-long/5611fd6972a4dfe3b1a01808c09bbfb2 to your computer and use it in GitHub Desktop.
# Attach-OnProcessStart
$ProcessName = "notepad.exe"
$ExceptionFilter = "ScanQueueTimeoutException"
Register-CimIndicationEvent -ClassName Win32_ProcessStartTrace -SourceIdentifier "ProcessStarted"
while ($true) {
$e = @(Get-Event)
if ($e.Count -lt 1) {
continue
}
$e | ForEach-Object {
Write-Host $_.SourceEventArgs.NewEvent.ProcessID ":" $_.SourceEventArgs.NewEvent.ProcessName
if ($_.SourceEventArgs.NewEvent.ProcessName -eq $ProcessName) {
Start-Process procdump -ArgumentList "-ma -e 1 -f $ExceptionFilter $($_.SourceEventArgs.NewEvent.ProcessID)"
}
}
$e | Remove-Event
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment