(Winows) Finding out which process has locked a file.

Tim Golden mail at timgolden.me.uk
Wed May 13 10:21:09 EDT 2009


CinnamonDonkey wrote:
> Hi all,
> 
> Does anyone know how I can programatically find out which process
> (resolved to human friendly string, i.e. executable) has a lock on a
> file.
> 
> I have a script running which occassionally fails because it is trying
> to delete a file in use by another process. When this happens I want
> it to log which process has the lock.
> 
> Since it tends to happen when I am never near the computer to catch
> it! :(


Usual place to look for these things is sysinternals (now part of
Microsoft). In particular, the handle util:

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

To get the same programatically you have to delve quite deep
into the NT low-level API. Not tried it myself.

TJG



More information about the Python-list mailing list