How do I find out which process is locking a file using .NET?
c#, file-locking
Solution
One of the good things about `handle.exe` is that you can run it as a subprocess and parse the output.
We do this in our deployment script - works like a charm.
Problem
I've seen several of answers about using Handle or Process Monitor, but I would like to be able to find out in my own code (C#) which process is locking a file. I have a nasty feeling that I'm going to have to spelunk around in the win32 API, but if anyone has already done this and can put me on the right track, I'd really appreciate the help. Update Links to similar questions - How does one figure out what process locked a file using c#? - Command line tool - Across a Network - Locking a USB device - Unit test fails with locked file - deleting locked file
Related problems
- What does this do? tasklist /m "mscor*"
- Command-line tool for finding out who is locking a file
- How do I delete a file which is locked by another process in C#?
- Is it possible to programatically find out what process is locking a file across a network
- Find out which process has an exclusive lock on a USB device handle