70

I would like to know who is locking a file (win32). I know about WhoLockMe, but I would like a command-line tool which does more or less the same thing.

I also looked at this question, but it seems only applicable for files opened remotely.

Community
  • 1
  • 1
JesperE
  • 63,317
  • 21
  • 138
  • 197

7 Answers7

102

Handle should do the trick.

Ever wondered which program has a particular file or directory open? Now you can find out. Handle is a utility that displays information about open handles for any process in the system. You can use it to see the programs that have a file open, or to see the object types and names of all the handles of a program.

fhe
  • 6,099
  • 1
  • 41
  • 44
  • 1
    Unfortunately, not quite. The very first invocation opens a window, which requires a valid COMCTL32.dll on the system - precisely what is missing on my machine. So, I am out of luck. – mark Jul 23 '11 at 16:21
  • 12
    @mark try running `handle /accepteula` the first time. This is a shortcut for accepting the EULA without the dialog. – John McCarthy Jan 02 '13 at 21:15
  • Alternatively, you can use registry to prevent this dialog coming out. For details to set up registry, this is the web URL: https://peter.hahndorf.eu/blog/post/2010/03/07/WorkAroundSysinternalsLicensePopups – Herbert Yu Apr 29 '15 at 19:17
  • 3
    GUI version of Handle. https://technet.microsoft.com/en-us/sysinternals/bb896653 – JustBeingHelpful May 04 '15 at 00:46
  • 1
    Running "handle.exe" returns a lot of files as being used by a certain process, but most of them i can delete while 'being used'. So handle clearly is not returning a list of locked files. – Alex Nov 21 '17 at 14:20
  • It's terribly slow. – NateS Feb 16 '20 at 11:57
21

handle.exe http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx

THis has helped me sooooo many times....

webclimber
  • 2,630
  • 4
  • 26
  • 36
  • 1
    Running "handle.exe" returns a lot of files as being used by a certain process, but most of them i can delete while 'being used'. So handle clearly is not returning a list of locked files – Alex Nov 21 '17 at 14:26
12

Download Handle.

https://technet.microsoft.com/en-us/sysinternals/bb896655.aspx

If you want to find what program has a handle on a certain file, run this from the directory that Handle.exe is extracted to. Unless you've added Handle.exe to the PATH environment variable. And the file path is C:\path\path\file.txt", run this:

handle "C:\path\path\file.txt"

This will tell you what process(es) have the file (or folder) locked.

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
  • 1
    After executing above line, the result is like that: notepad.exe pid: 6828 BC8: C:\path\path\file.txt If you want to close the specified handle, execute: handle.exe -c BC8 -p 6828 – ionat May 23 '17 at 20:00
  • I would suggest asking a new question on StackOverflow. And provide ALL details. The exact command and exact output. Feel free to reference this ticket. Also state what your security is (ie: Administrator, non administrator). – JustBeingHelpful May 23 '17 at 20:02
  • I can run "handle.exe some.dll" and in many cases I can delete some.dll even if handle reports a process using it. So clearly handle does not return a list of locked files – Alex Nov 21 '17 at 14:27
  • Is the exe not locked, or are the dll files not locked? – JustBeingHelpful Nov 22 '17 at 03:08
  • handle.exe lists dlls that can be deleted – Alex Nov 23 '17 at 12:59
2

In my case Handle.exe did not help. Simple program from official Microsoft called Process Explorer was useful. Just open as administrator and press Ctrl+f, type part of file name it will show process using file.

Augustas
  • 1,167
  • 21
  • 31
1

Handle didn't find that WhatsApp is holding lock on a file .tmp.node in temp folder. ProcessExplorer - Find works better Look at this answer https://superuser.com/a/399660

Pawel Cioch
  • 2,895
  • 1
  • 30
  • 29
1

enter image description here

Computer Management->Shared Folders->Open Files

Community
  • 1
  • 1
Halim
  • 2,090
  • 2
  • 16
  • 9
0

I have used Unlocker for years and really like it. It not only will identify programs and offer to unlock the folder\file, it will allow you to kill the processing that has the lock as well.

Additionally, it offers actions to do to the locked file in question such as deleting it.

Unlocker helps delete locked files with error messages including "cannot delete file," and "access is denied." Video tutorial available.

Some errors you might get that Unlocker can help with include:

  • Cannot delete file: Access is denied.
  • There has been a sharing violation.
  • The source or destination file may be in use.
  • The file is in use by another program or user.
  • Make sure the disk is not full or write-protected and that the file is not currently in use.
gwnp
  • 1,127
  • 1
  • 10
  • 35