Is there a way to handle locked file from command line and release it? [closed]
Asked Answered
P

2

13

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
Pushcart answered 20/5, 2012 at 9:9 Comment(7)
What's the real problem?Medick
-1! Bad question for stackoverflow.com .. must be asked on superuser.comAbettor
@Abettor Did you know that you can use the "flag" link underneath the question's tags to suggest that it be migrated to another, more appropriate site?Lewiss
A guy asks if a specific feature in the Windows API exists so he can write a utility program, and that's not a programming question and belongs on superuser? I don't get it.Carpometacarpus
The question doesn't ask if the feature exists in the Windows API, he asks for a way to do it by the command line. The command line is not a programming language, or a programmatic interface. It's a user interface, just like Windows Explorer.Lewiss
This is a task that a programmer is likely to have to do. If you must move the question, go ahead and move it. But for a programmer who just wants to get something done, closing a question like this just gets in the way. It is frankly by far the most annoying thing that regularly happens on SO.Warthog
@CodyGray - There are probably several people who hang in the [cmd] tag that might disagree with you.Fyrd
L
23

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.

Lewiss answered 20/5, 2012 at 10:5 Comment(2)
Thanks, but it seems that it harder to work with handle.exe, because it should to get the pid, i want to create a batch file that know to search foreach a file is in the specific folder and unlock it..Pushcart
@David Harder than what? That seems like a really strange plan. If applications are using those files and you close all the handles, you've got a serious problem on your hands.Lewiss
M
-4

No, you can't you have to close the application holding the lock first. Unlocker may help you locate the source of the lock - if it's a crashed application then you'll be able to terminate it's process.

Medick answered 20/5, 2012 at 9:15 Comment(2)
If Unlocker can do it, then there is a programmatic way to do it. Otherwise, Unlocker wouldn't work.Woodbury
Unlocker is terrible. Lock Hunter is at least usable.Berwick

© 2022 - 2024 — McMap. All rights reserved.