Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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" } }

share|improve this question

1 Answer 1

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.

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

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.