views:

66

answers:

1

Using Process.Start, I am starting various IE8 and Firefox (3.5) processes which I keep a Process instance for.

A little while later in the application, I'll use the Process instances' MainWindowHandle property to target the window for use with some platform API functions via P/Invoke.

However, both IE8 and Firefox will kill the second process I start, then restart it using the first. This means that my Process instance now refers to a closed process, and so HasExited is true and MainWindowHandle is equal to IntPtr.Zero.

Here's an example of what happens (I'm using IE8 for this example):

  • Process.Start is called with "iexplore.exe"
  • Process starts and continues running
  • Process.Start is called again with "iexplore.exe"
  • First process continues running, but the second is killed immediately
  • Another iexplore process is started (presumably by the first iexplore process).
  • During this time, the user sees the second IE window only after the second process is killed and restarted.

I understand why these browsers behave this way, but it does create a problem for me if I want to control the created process later on.

Has anyone come across this problem before? How would you recommend getting a reference to the process back? I thought about using GetProcessesByName and iterating through their window titles, but unfortunately the titles may be the same as the first process launched.

Note: IE8 was the first version of IE to use process separation and so only IE8 behaves this way, I don't have this problem with IE7, unfortuantely I need IE8 support as well.

A: 

I have used the Running Object Table (ROT) in the past to find a specific process and control it.

http://www.codeproject.com/KB/COM/ROTStuff.aspx

Eric J.