Tool to determine what has locked a file
Problem
Every once in a while when I try to remove a file I have been working with, Windows tells me I cannot remove it, because some application is still using it. Sometimes it's just my own stupidity, and closing the app I was working with releases the file, but sometimes I cannot for the life of me imag…
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Identify and Release File Locks in Windows
Windows locks files when they are in use by applications or processes. This can happen due to background processes, services, or even the application itself not releasing the file handle properly. Tools like 'Handle' from Sysinternals can help identify which process is holding the lock.
Awaiting Verification
Be the first to verify this fix
- 1
Download Sysinternals Handle Tool
Visit the Sysinternals website and download the Handle utility, which allows you to see which processes have handles to the files.
bashcurl -O https://live.sysinternals.com/handle.exe - 2
Run Handle to Identify Locking Process
Open Command Prompt as Administrator and navigate to the directory where you downloaded 'handle.exe'. Use the command 'handle <filename>' to find out which process is locking the file.
bashhandle yourfile.txt - 3
Terminate the Locking Process
Once you identify the process ID (PID) that is locking the file, you can terminate it using Task Manager or the command line. To terminate via command line, use 'taskkill /PID <PID>'.
bashtaskkill /PID 1234 - 4
Delete the File
After terminating the process, you should now be able to delete the file without any issues. Use File Explorer or the command line to remove the file.
bashdel yourfile.txt - 5
Verify File Deletion
Check the directory where the file was located to ensure that it has been successfully deleted. You can also use the command 'dir' to list files in the directory.
bashdir
Validation
Confirm that the file has been deleted and that no error messages appear when attempting to delete it again. Optionally, re-run the handle command to ensure no processes are locking the file.
Sign in to verify this fix