Question

How do I get the list of open file handles by process in C#?

How do I get the list of open file handles by process id in C#?

I'm interested in digging down and getting the file names as well.

Looking for the programmatic equivalent of what process explorer does.

Most likely this will require interop.

Considering adding a bounty on this, the implementation is nasty complicated.

 45  65072  45
1 Jan 1970

Solution

 26

Ouch this is going to be hard to do from managed code.

There is a sample on codeproject

Most of the stuff can be done in interop, but you need a driver to get the filename cause it lives in the kernel's address space. Process Explorer embeds the driver in its resources. Getting this all hooked up from C# and supporting 64bit as well as 32, is going to be a major headache.

2008-10-07

Solution

 12

You can also run the command line app, Handle, by Mark Rusinovich, and parse the output.

2008-10-07