Identify process using a file

Amy picture Amy · Dec 19, 2008 · Viewed 47.7k times · Source

I have been trying to figure out how to programmatically identify the process that has a lock on a particular file. I've searched through the Win32 API and WMI, but so far I can't find anything. I know it's possible - Sysinternals is able to list every resource accessed/locked by every process on the system.

Can anyone drop me a hint?

Answer

thejoshwolfe picture thejoshwolfe · Jan 11, 2013

You can use handle.exe from Sysinternals.

Something like:

> handle /accepteula C:\path\to\directory
...
program.exe           pid: 1234   type: File           2E4: C:\path\to\directory
...

Thanks to https://stackoverflow.com/a/599268/367916 .