Loading...

Powershell Unlock File (2026)

You can use PowerShell to call handle.exe with the -c flag to forcibly close a file handle:

Run this PowerShell one-liner to find which process is locking C:\path\to\your\file.pdf : powershell unlock file

# Graceful stop (sends close signal) Stop-Process -Id 8764 Stop-Process -Id 8764 -Force You can use PowerShell to call handle

function Test-FileLock { param([string]$FilePath) try { $file = [System.IO.File]::Open($FilePath, 'Open', 'Read', 'None') $file.Close() return $false # File is not locked } catch { return $true # File is locked } } Test-FileLock "C:\locked.docx" You need to know exactly which application (Word,

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.

You need to know exactly which application (Word, Notepad, a rogue service) is holding the lock before acting. 3. The "Force Unlock" via Safe Volume Opening For advanced scenarios, you can use .NET's FileShare.None method. This doesn't break an existing lock, but it can prevent future locks or test if a file is locked: