-
-
Save clavoillotte/1424594fb2a17753c36505663d671933 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module NtObjectManager | |
<# | |
Function to kill all processes which are using a locked file. | |
#> | |
function Kill-FileLocker { | |
param( | |
[Parameter(Mandatory)] | |
[string]$Path | |
) | |
Set-NtTokenPrivilege SeDebugPrivilege | Out-Null | |
Use-NtObject($file = Get-NtFile $Path -Win32Path -Access ReadAttributes) { | |
foreach($id in $file.GetUsingProcessIds()) { | |
Use-NtObject($p = Get-NtProcess -ProcessId $id -Access Terminate) { | |
Write-Host "Killing process $p" | |
$p.Terminate(0) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment