Handle is a free command line software that lets you view the name of the process or program that currently has access to a particular file or directory (folder). It can also show you a list of all open handles, lets you filter out the handles for a specific folder or file, shows you the owner of the handles, can close a handle for you. It can also dump the information for all the handles open in the system like, registry keys, ports, processes, threads etc., and not just files and folder. This can be a handy tool while you’re troubleshooting issues you’re facing with your computer or just to see which process or program has access to a particular file or folder.
What are file handles?
When an application request access to a file or a folder, the operating system assigns a number or an id that we call “handles“. Once the program is done using the file, it can simply close the handle. Some programs can also lock the handle to make it unavailable for other applications. You might have come across situations where you’re trying to delete a file but Windows gives you an error telling you that the file is in use and cannot be deleted. This is because the file handle for the particular file you’re trying to delete is still in use.
How to use Handle?
Handle is a command line utility and does not have an interface. We would have to tell it what to do via arguments or passing parameters to it. Before we get to the parameters, a quick note for people who don’t know how to access the command prompt. To get to command prompt, press the Windows Key and “R” key to bring up the Run Box. We can simply type in “cmd” in this box to bring up the command prompt.
Good to have “Arguments”
We’re going to talk about simple to use parameters (arguments) to view the windows file handles using this simple but useful tool.
To simple view the windows file handles that are currently open:
By simply typing the name of the tool, it dumps out the windows file handles currently open however it scrolls away from the screen so quickly that you just get a glimpse of what happened on the screen. So you can add “| more” to the end of “handle” to pipe the output to “more” tool and it will display the output per page. You can press the “Enter” key to view scroll a line or “Space” to view the next page.
handle or handle | more
View all the handles (registry keys, processes, threads etc.)
By default, Handles only shows you the Windows file handles currently in use. However, you can get all the handles including registry keys, processes, threads etc., to be displayed on the screen. You can achieve this by using the “-a” option in the command line.
This is how you do it:
handle -a OR handle -a | more
Owner of the handle
If you wish to see the owner of a particular windows file handle, for a process, thread, etc., you can use the “-u” option in the command line.
This is how you do it:
handle -u OR handle -u | more
Search for handles from an application or process
Handle can let you search for handles opened by a specific process currently running. You can even type the few letter of the process and Handle will let you view all the handles matching it. This is how we do it:
handle -p fox
What I am looking for is the “Foxit PDF reader” currently running and my e-book named “placesofpower.pdf” opened with Foxit PDF Reader.
Relating to what we did above, we can also search for the windows file handle for my EBook “placesofpower.pdf” just by typing the name of the file next to “Handle”. Again, it does not require exact name and just typing a part of it would be fine with it.
This is the command for it:
Dump it all to a file
You can dump the output to a file by using the ‘>’ operator followed by the filename. This is how we do it:
handle -u -a > allhandles.txt
This above command will dump all the handles (not just the windows file handles) with the owner’s information to a file named “allhandles.txt”
Handle can come handy while you’re troubleshooting issue or just curious to know which process currently has access to a file or folder. This can also be useful in case you’re trying to delete a file or folder but are not able to delete it. You could check the windows file handle for it to check which application is currently using it. You can dump the output to a file for further analyse or send it to someone (a technician or a geek) to get it checked. It’s a lightweight tool and does not require any installation so you can give it a little space or your hard drive and use it when it’s time.
You might also want to read about ProcessExplorer – an excellent replacement for Windows Task Manager.