New Russinovich tool scans for open file references from command line

I've written before about utilities that search for open file or directory processes and allow you to gracefully (or forcefully) close those connections. Most of these types of programs are friendly GUI-driven products that snap into Windows Explorer's right-click context menu. But I thought I'd talk about a recently updated tool that's (a) a command-line item and (b) written by someone who's created easily some of the best third-party add-on utilities for Windows as a whole.

I speak of Mark Russinovich and his command-line tool

Requires Free Membership to View

Handle, now in version 3.30. Handle 3.3 helps if you're trying to delete or move something and a program has stupidly left a handle open on a given file even if it's not actually doing anything with it. This functionality is also available through Russinovich's now-classic Process Explorer. But Handle repackages the handle-specific functions in a way that they can be used as part of a script or with better granularity than what you'd be able to get from the Process Explorer UI.

If you run Handle 3.3 without any command-line parameters, it'll simply dump out a list of all the open handles in the system -- which can be a very long list, so be warned. (Out of curiosity, I dumped out my own desktop's open-handles list to a text file and got a file 110K in size.)

If you use the -p switch in conjunction with a process name (a partial name is OK), you'll get a list of all the handles for all the processes that match that name. Each handle also has an associated hexadecimal ID, shown to the left of the filename. Example:

28A: File (---) D:\PORTAB~1.0\PORTAB~1\FIREFO~1\App\firefox\chrome\browser.jar

This file (dumped from a running instance of Portable Firefox, from the PortableApps collection) has a hex ID of 28A.

When you want to close a handle, use the -c switch to specify which handle, and you need to specify an exact process ID number with the -p switch. If I wanted to close this particular handle, I'd use the command line handle –c 28A –p 4056 (with 4056 being the process ID for Firefox here).

It's also possible to scan for handles by file rather than executable. If you specify a filename as the first argument for the program, you'll see all the processes that have that file open as a handle. Specify a directory and Handle will iterate through everything in the directory that has a handle open on it.

Keep in mind that terminating an open handle is always a slightly risky proposition. A program that doesn't accept such a thing gracefully may crash, and if you close an open handle on a system component, you can potentially hang the system up entirely.

Finally, note that you'll need administrative privileges to run Handle 3.3; in Vista, you can only run Handle from an elevated command prompt.

Serdar Yegulalp is editor of Windows Insight (formerly the Windows Power Users Newsletter), a blog site devoted to hints, tips, tricks and news for users and administrators of Windows NT, Windows 2000, Windows XP, Windows Server 2003 and Vista. He has more than 12 years of experience working with Windows, and contributes regularly to SearchWinComputing.com and other TechTarget sites.

This was first published in November 2007

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.