views:

73

answers:

1

How to get PIDs of processes that are using a given file name and mutex name? (Not by custom kernel driver, but in C# in user mode.)

UPDATE: Thanks to Daniel Renshaw I found a script that lists all handles with PIDs. (Using a not undocumented and unfrozen functions.)

+1  A: 

The following two SO questions may be of use:

http://stackoverflow.com/questions/317071/how-do-i-find-out-which-process-is-locking-a-file-using-net

Summary: use handle.exe and parse the output (i.e. not a great solution)

http://stackoverflow.com/questions/1947312/win32-how-to-get-the-process-thread-that-owns-a-mutex

Summary: may not be possible in user mode without using deprecated or undocumented functions (but some smaple code is provided in this question).

Daniel Renshaw
Maybe I am wrong, but `handle.exe` does not seem to work well. I was trying running from a cmd `handle C:\Windows\System32\cmd.exe`. It says: `No matching handles found.` (I am using latest version.) And also does not seem to work for mutexes.How to make the script in the second post to print the handle names?
TN