Find out which process is locking a file or folder in Windows
How can I find out which process is locking a file or folder in Windows?
For instance, when trying to delete a folder, Windows reports this:
The action can't be completed because the folder is open in another program
Happens the same with a file, but how do I find out what program or application is currently using it and preventing me from deleting the file or folder?
PowerShell method:
if ((Test-Path -Path $FileOrFolderPath) -eq $false) {
Write-Warning "File or directory does not exist."
}
else {
$LockingProcess = CMD /C "openfiles /query /fo table | find /I ""$FileOrFolderPath"""
Write-Host $LockingProcess
}
The openfiles
command needs to have support for local files enabled, by running openfiles /local on
and restarting.
More details How to find out which process is locking a file or folder in Windows archive
You can use the Resource Monitor for this which comes built-in with Windows 7, 8, and 10.
- Open Resource Monitor, which can be found
- By searching for Resource Monitor or resmon.exe in the start menu, or
- As a button on the Performance tab in your Task Manager
- Go to the CPU tab
- Use the search field in the Associated Handles section
- See blue arrow in screen shot below
When you've found the handle, you can identify the process by looking at the Image and/or PID column.
You can then try to close the application as you normally would, or, if that's not possible, just right-click the handle and kill the process directly from there. Easy peasy!
A couple of options:
Microsoft/SysInternals Process Explorer - Go to Find > Find Handle or DLL. In the "Handle or DLL substring:" text box, type the path to the file (e.g. "C:\path\to\file.txt") and click "Search". All processes which have an open handle to that file should be listed.
WhoLockMe - Explorer extension which adds a right-click menu option
N.B. WhoLockMe appears to not work with Win 10 (at least I have been unable to register it with either of the 32- or 64-bit versions of regsvr32.exe).
Have a look at Process Explorer (procexp.exe
).
From its introduction:
Ever wondered which program has a particular file or directory open? Now you can find out.
To find out what process is using a specific file follow these steps:
-
Go to Find, Find Handle or DLL.. or simply press Ctrl+F.
-
Enter the name of the file and press Search.
-
Process Explorer will list all processes that have a handle to the file open. Click on an entry to focus the process in the main window.
-
Optionally, you can then even close the handle manually through the lower pane (Ctrl+L):
LockHunter can unlock any handlers that may have locked your files or folders. Unlike similar freewares, it supports both 32 and 64-bit Windows.
It is a free tool to delete files blocked by something you do not know. LockHunter is useful for fighting against malware, and other programs that are blocking files without a reason. Unlike other similar tools it deletes files into the recycle bin so you may restore them if deleted by mistake.
- Shows processes locking a file or folder
- Allows to unlock, delete, copy or rename a locked file
- Allows to kill locking process
- Allows to remove locking processes from hard drive
- Integrates in to Explorer menu
- It deletes files into the recycle bin, so you may restore them if deleted by mistake
- Supports both 32 and 64bit Windows