4

I need get the HANDLE or HWND of a hidden window to terminate it with EndTask((HWND)hProc,TRUE,TRUE);. I used all ways listed below but none of them work. When I manually set a handle to a hidden window with spy++, this worked correctly.

NOTE: This window not show with ShowWindow() and then use FindWindow(). How does spy++ get and show these handles?

enter image description here

I used:

  1. FindProcessId

    and then

    hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, id);
    

    or

    hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
    
  2. Create process not work: access denied.

  3. FindWindow() does not work for this hidden window.

How can I get the handle for the hidden window so I can terminate the process?

Mehdi Hosseinzadeh
  • 1,160
  • 11
  • 25
user1833748
  • 57
  • 1
  • 4
  • 4
    Try using [`EnumWindows()`](http://msdn.microsoft.com/en-gb/library/windows/desktop/ms633497(v=vs.85).aspx) to locate the window. – hmjd Nov 19 '12 at 08:47
  • 1
    This is some sort of enterprisey program, IDM means Identity Driven Manager. You can fully expect it to block attempts to mess with it. You'll need to work with the LAN admin if it gets in the way, although the odds are high that it is there explicitly to stop you from doing what you want to do. – Hans Passant Nov 19 '12 at 14:50
  • `EndTask((HWND) hProc, TRUE, TRUE);` That doesn't make sense. You cannot cast a process handle to a window handle. Also, `EndTask` is deprecated. Also, `EndTask` doesn't necessarily stop the program, but simply tries to close (and/or destroy) the specified window. Many programs don't stop when one of their windows is destroyed. What are you really trying to do? – Adrian McCarthy Nov 19 '12 at 21:34

1 Answers1

2

FindWindow will search any type of Windows and it does not matter it's hidden or not.

Maybe your problem with FindWindow is that, window you were looking for, was child of another one and for this reason you are unable to find that.

So you should use FindWindowEx and search into children's windows.

Mehdi Hosseinzadeh
  • 1,160
  • 11
  • 25