title: Getting process ID of a SHDocVw.InternetExplorer spawned IE8 process
body: <p>I'm using <a href="http://msdn.microsoft.com/en-us/library/aa752084(VS.85).aspx" rel="nofollow noreferrer">SHDocVw.InternetExplorer</a> to launch IE in my code. In certain cases InternetExplorer.Quit() doesn't work. I have <a href="https://stackoverflow.com/questions/7077003/debugging-shdocvw-internetexplorer-quit-not-closing-iexplore-exe-process">tried several things</a> to make Quit work but without success. I'm now resorting to Process.Kill. </p>
  
  <p>Now if a manually launched instance of IE8 is already running when SHDocVw.InternetExplorer is used to launch another one the new one gets created as a child process of the existing IE:</p>
  
  <p><img src="https://i.stack.imgur.com/2l8RM.png" alt="SHDocVw.InternetExplorer spawned IE is a child of the existing IE"></p>
  
  <p>The SHDocVw.InternetExplorer IE is process id 996 on the screenshot, the manually launched one is 3388 plus its child 2876.</p>
  
  <p>Now if I use <a href="http://msdn.microsoft.com/en-us/library/bb268219(VS.85).aspx" rel="nofollow noreferrer">InternetExplorer.HWND</a> to retrieve the window handle of my IE and then <a href="http://msdn.microsoft.com/en-us/library/ms633522(VS.85).aspx" rel="nofollow noreferrer">GetWindowThreadProcessId</a> to get the process ID I end up with 3388, the parent IE process ID when what I want is 996, the InternetExplorer.HWND launched IE process ID.</p>
  
  <p>I'm not sure on which step it gets wrong.<br>
  <em>Should I be retrieving the HWND in a different way or the process ID? Or both?</em></p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit:</strong> I've just tried sending <code>WM_CLOSE</code> to the HWND and it closed the parent IE. I suppose it  means I'm getting a wrong HWND?</p>
  
  <p><strong>Edit:</strong> It may be worth noting that only the manually launched IE is visible when I do the closing. Would this mean I'm getting the HWND of the only visible IE therefore?</p>