Ever tried deleting, moving or renaming a file and got a terse message from Windows saying, you can’t ! With the reason being that the said file is in use by another process !
If you’ve ever been faced with one of those “Cannot delete a file because it is in use by another program” dialogue boxes, you’ll know how frustrating that can be.
The fact that you’ve closed every other program running on the system and still you get that message is even more annoying. So much for multitasking !
Windows, like all operating system, has no control over who requests to open a file. And when an application closes, it assumes that it’ll close and release control over all the files it opened. That sometimes doesn’t work. If an application crashes midway, or because of a bug forgets to close a file that it opened for use, Windows continues to assume that the file is still open by that application. And so if you go on to delete, move or do anything destructive with that file, you get this dreaded message.
The problem is that Windows, by default, does not come bundled with any utility to help you overcome this problem. Although someone at Microsoft did recognize the need for such a tool and released the excellent Sysinternals Process Explorer.
Process explorer is a full featured replacement for the simple Task manager that is bundled with Windows. It, not only gives you much more info about the processes running on your system, it also gives you much more visibility into what exactly is each process doing, how many resources it is consuming and what other resources does it depend on.
Among, the many properties of an application that Process Explorer displays, the one that is most useful to us is the ability to display the open file handles.
Under Windows, whenever an application wants to access or open a file, it does so using something called a File handle, which is nothing but a pointer to the particular file in the memory. When an application crashes, hangs or is unable to close the file handle that it opened, users start getting the File in Use message (when they try to access that file, of course).
Now, we’ll see how, using Process Explorer, we can find out out which process has a particular file open and how we can force the application to close it.
Click on Find->Find Handle or DLL or press CTRL+F.
Enter the name of the file that you’re trying to open and click on Search.
Process Explorer will display the the name of the process that has the file opened. Click on it, and it’ll highlight the process and the open handle in the main window. Click on Cancel and go to the main Window.
Right click on the Handle name and select Close Handle.
Voila ! You should now be able to delete the particular, modify it or do whatever it is that Windows was preventing you from doing with it.
SysInternal Process Explorer is a free download and is, in my opinion, one of those extremely useful tools that should be present on every Windows install.