Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I tried Unlocker 1.9.1 but it doesn't work correctly for me on Windows7 (worked ok on Windows XP) and also I tried LockHunter 2.0.2.103 x64 and reported a bug but .... LockHunter actually unlocks the file from GUI but not from command line.

So I want to use handle.exe by SysInternals to unlock one file "TestPro.log". I know the absolut path if it helps. I can list and all processes that locked the file by executing

C:\Windows\system32>c:\edutester\progs\handle testpro.log
java.exe           pid: 2120   type: File           338: C:\Users\Public\TestPro
\TestPro Automation Framework\Logs\TestPro.log
java.exe           pid: 1004   type: File           934: C:\Users\Public\TestPro
\TestPro Automation Framework\Logs\TestPro.log

What I need to know how to unlock the file using above info from command line automatically. No user intervention is possible.

  • Windows 7 64bit
  • Microsoft Windows [Version 6.1.7601]
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can use handle.exe once to list the PIDs and handles, then again multiple times to close each one.

Use the for /f command to loop through the result of the first command. I don't have a Windows machine handy to test on, but it should look something like this:

From a batch file:

for /F "tokens=3,6 delims=: " %%I IN ('handle.exe -accepteula TestPro.log') DO handle.exe -c %%J -y -p %%I

From the command-line:

for /F "tokens=3,6 delims=: " %I IN ('handle.exe -accepteula TestPro.log') DO handle.exe -c %J -y -p %I
share|improve this answer
    
I will happily try/test :-) Thank you –  Radek Oct 12 '12 at 3:23
    
I cannot make it work. Your code gives me ('handle.exe was unexpected at this time. I think there is missing in before ('handle.exe was unexpected at this time. But then %%J contains :` so it's not valid argument for handle.exe –  Radek Oct 12 '12 at 5:04
    
Yeah, I remember having trouble getting the command exactly right, but I can't remember what I did off the top of my head. I'm trying to get access to my batch file again so I can update my answer with the right syntax. –  Stephen Jennings Oct 12 '12 at 5:23
    
@Radek I updated my answer with the actual code I used. Looks like I got %%I and %%J mixed up, and we need the colon as a delimiter. Try this and see how it goes. –  Stephen Jennings Oct 12 '12 at 15:08
    
Works nicely (both batch file & command line versions) if cmd started as administrator. Any idea how I can make it work as a part of my overnight automation testing? runas doesn't work for me in this case. –  Radek Oct 14 '12 at 22:59
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.