Delete file that locked by Windows Process

  • by

Steps to delete file that locked by Windows Process

  1. Open Task Manager – Performance – Open Resource Manager

FileLock-01

  1. Go to CPU – Associated Handles and search for the file which locked by Windows Process

FileLock-02

Right click on the process which locked the file to end / kill it, and you should be able to delete the file in Windows Explore now

The PowerShell way

  1. Download Get-FileLockProcess.ps1

  2. Import the downloaded Function, End the process and delete the file

#Import Function
. C:\MyPowerShell\Get-FileLockProcess.ps1

$File = "C:\Temp\SendEmail.csv"
$Process = Get-FileLockProcess -FilePath $File

#Kill the process
Stop-Process -Id $Process.id 

#Wait for 5 seconds 
Start-Sleep 5

#Delete the file
Remove-Item $File -Force