Is there a way to handle locked file from command line and release it?

David Michaeli picture David Michaeli · May 20, 2012 · Viewed 31.3k times · Source

Is there a way to detect locked files in specify folder and release them by command line?

Something like this in pseudo-code:

for file in folder do
unlock file

Answer

Cody Gray picture Cody Gray · May 20, 2012

Yes, this is possible using a free utility called Handle, by Mark Russinovich.

It can be download here from Microsoft.

This runs from the command line, and will tell you which program has a particular file or directory open, based on whether it has an open handle to that resource.

By running handle.exe with the -c flag, you can also force the specified handle closed, which will unlock the resource. But fair warning: this will likely cause the application using the resource to crash, perhaps even the entire system to become unstable. So I wouldn't make a habit of doing this; only use it for special cases like debugging where you expect some instability.