Thread: Is there a way to enumerate handles?

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195

    Is there a way to enumerate handles?

    I have a piece of code that is behaving badly. Unfortunately I didnt write it and I dont have access to the source code, just the OBJ. The problem is that this code is leaking handles and I need to close them post facto. Is there a method for enumerating the allocated handles so that I can check their state and close them if they are signalled?
    Last edited by abachler; 10-29-2007 at 12:42 PM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    sysinternals.com have tools that "dig around in the kernel", such as "Process Explorer". I'm not sure if this is:
    1. exactly what you want
    2. roughly what you want
    3. not at all what you want

    But I think it's worth getting for the odd occasion when some application says "I can't open <filename> because it's locked", and it turns out that some cruddy app has that file open - you can FORCE close the file from Process Explorer.

    You can also look at all sorts of handles in it, so it may help you.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Interesting, but Ill have to go with option 3. What I need is a way to programmatically enumerate the handles, so I can close them from my application.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    What I need is a way to programmatically enumerate the handles
    You'll have to use the undocumented (NT)ZwQuerySystemInformation and (NT)ZWQueryObject functions.

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    thx

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    complete code posted on news://comp.os.ms-windows.programmer.win32
    a long time ago...

  7. #7
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    ah usenet, those were the days.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with DB handles
    By pokks in forum C Programming
    Replies: 4
    Last Post: 01-04-2006, 12:06 PM
  2. organizing window handles
    By FOOTOO in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 11:53 PM
  3. Handles to visible programs
    By Snip in forum Windows Programming
    Replies: 3
    Last Post: 03-26-2005, 08:52 PM
  4. [code] Enumerate IE instances and retrieve interfaces.
    By anonytmouse in forum Windows Programming
    Replies: 1
    Last Post: 05-05-2004, 08:01 AM
  5. Enumerate type
    By dv007 in forum C Programming
    Replies: 8
    Last Post: 07-15-2002, 03:32 PM