10

How do you go about querying running processes to find out what folders or files they have locked? (i.e. you go to eject a drive and you're told that it can't be ejected because it's in use)

I'd like to either get an "off the shelf" download, or write a .NET 3.5 app to do this (primarily a Windows question).

CodeMonkey1313
  • 15,717
  • 17
  • 76
  • 109
  • http://stackoverflow.com/questions/225802/how-to-determine-which-process-is-holding-a-file-in-windows – raven Jul 05 '09 at 21:15

4 Answers4

27

Process Explorer will show you this. Ctrl-F will let you search for a file and list the process(es) that have that file open/locked. You can then close that handle using Process Explorer.

There's also a command line utility called oh.exe available for download. See here for more details

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • 1
    Process Expolorer is my tool of choice for this. It also allows you to close the handle. – Marnix van Valen Jul 05 '09 at 18:31
  • Good point re. the handle closing. I'd forgotten that. Answer amended – Brian Agnew Jul 05 '09 at 18:35
  • 1
    However, don't close the handle unless you're willing to have the program crash, freeze, burn your house down or hold all your data ransom. The program won't expect the handle to close until it decides to close it, so who knows what havoc it will cause when this assumption is violated :) – Patashu Feb 06 '13 at 22:43
5

LockHunter is a great context menu tool for Windows.

CodeMonkey1313
  • 15,717
  • 17
  • 76
  • 109
2

One of the first things I put on my Windows dev machines is WhoUses. It's nice because it's open source too.

marcc
  • 12,295
  • 7
  • 49
  • 59
0

http://www.emptyloop.com/unlocker/ (freeware) has a special UI for exactly this situation.

Rutger Nijlunsing
  • 4,861
  • 1
  • 21
  • 24