windowshandle

How to enumerate a process's handles?


Is there a way to enumerate a process with a given PID in Windows, and get a list of all his opened handles (locked files, etc.)?

EDIT: I don't care about language. If it's in .NET, I'd be glad, if it's in WinApi (C), it won't hurt. If in something else, I think I can rewrite it :-)


Solution

  • I did a deep googling and found this article (webarchive).

    This article gave a link to download source code (webarchive):

    I tried method in NtSystemInfoTest.cpp ( downloaded source code ) and it worked superbly.

        void ListHandles( DWORD processID, LPCTSTR lpFilter )
    

    The code has following declaimer:

    // Written by Zoltan Csizmadia, zoltan_csizmadia@yahoo.com
    // For companies(Austin,TX): If you would like to get my resume, send an email.
    //
    // The source is free, but if you want to use it, mention my name and e-mail address
    

    I hope this helps you.