You can use PowerShell to call handle.exe with the -c flag to forcibly close a file handle:
This is useful for scripts that need to wait until a file is free (e.g., a backup script waiting for a database to release a log file). Warning: This is risky. Do not run this on your C: drive. powershell unlock file
Always save your work before force-unlocking files. A forced handle close is like unplugging a hard drive—it works, but data loss is possible. You can use PowerShell to call handle
Download handle64.exe and place it in your C:\Windows\System32 folder or a path of your choice. Always save your work before force-unlocking files
function Unlock-File { param( [Parameter(Mandatory)] [string]$FilePath, [string]$HandlePath = "handle64.exe" ) if (-not (Test-Path $HandlePath)) { Write-Error "handle64.exe not found. Download from Sysinternals." return }
Run this PowerShell one-liner to find which process is locking C:\path\to\your\file.pdf :
Stop-Process -Name explorer -Force Start-Process explorer.exe You know the lock is caused by Explorer (e.g., an image or video file preview stuck open). 2. Finding the Culprit: Identifying the Locking Process PowerShell can't directly break a lock without help, but it can tell you who has the lock. For this, we use the Handle tool from Sysinternals (Microsoft’s official utility suite).