up vote 1 down vote favorite
share [g+] share [fb]

is there a way to use the windows power shell to trace what application has a resource lock on a file?

Here is what i am looking for:

  • A command line or script to show the application that has a lock on a file.
  • A bonus to the above wold be detection of the user account that has the lock and how long the lock has persisted.

Follow up:

  • There is a power tool by SysInternals that will allow you to capture a full dump in the command shell of the above.
  • I found a script that appears to do the job as well (replace with the full path and file you want to see):

    PS> $handle = handle

    PS> foreach ($line in $handle) { if ($line -match '\S+\spid:') { $exe = $line } elseif ($line -match '') { "$exe - $line" } }

link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

Handle from Windows Sysinternals is a command line utility that can be used to determine what handles have a lock on a file. You can run handle from the command line with

handle c:\fileToCheck

Or you could write a PowerShell script to wrap the functionality of handle.

link|improve this answer
I just found the same thing and updated the post with the script. Thanks. – Ioxp Jul 20 '09 at 13:49
feedback

Your Answer

 
or
required, but never shown

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