Advertisement
guyrleech

Close all open handles for a process

Jun 26th, 2020
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Need to have SysInternals handle/handle64.exe in the current working directory
  2. ## USE WITH EXTREME CAUTION - LIKELY TO CAUSE INSTABILITY
  3. [int]$counter = 0 ; if( ($process = Get-Process -name svservice) -and !($process -is [array])){ & .\handle64.exe -a -p $process.id -nobanner -accepteula | Where-Object { $_ -cmatch '\s?([A-F0-9]*):\s' -and ! [string]::IsNullOrEmpty( ( $handle = $Matches[1] ) ) } | ForEach-Object { & .\handle64.exe -c $handle -y -p $process.id -nobanner  ; if($?){$counter++}}};"Handles closed $counter"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement