When accessing Process.MainWindowTitle as follows...
Process[] processes = Process.GetProcessesByName( "iexplore" );
...and then loop over the resulting array, I always end up with the MainWindowTitle
being empty for all but one item in the array. In my case I've got two Internet Explorer windows open, one with a single tab and one with two tabs in it.
Running my code I always get the MainWindowTitle for the window and tab that I had last active - all the others remain empty. The strange thing is that the process ID in which the MainWindowTitle is filled is always the same - if I activate the other IE window or tab before running my code, the process ID is always the same:
if ( !processes.Any() )
{
MessageBox.Show( "TODO - No matching process found" );
return;
}
if ( processes.Count() > 1 )
{
foreach ( Process currentProcess in processes )
{
// More than one matching process found
checkedListBox1.Items.Add( currentProcess.Id + " - " + currentProcess.MainWindowTitle + " - " + currentProcess.ProcessName );
}
return;
}
Output could therefore be for the first run like:
Next run (with the other IE window selected beforehand):
I've read about this post, but I didn't get any further with my problem (and it seems to go into a somewhat different direction anyway).
Why do I always only get one non-empty MainWindowTitle?
Remember that internet explorer uses a hosting model - one iexplore.exe instance hosts the internet explorer frame, the other iexplore.exe instances just display the contents of tabs.
The only IE instance with a top level window is the iexplore.exe process which hosts the frame.
This article discusses the multi-process architecture of various web browsers. As I understand it, browsers are moving to a multi-process model - that way a failure in one web page won't affect other pages. This article goes into more detail about IE's multi-process model.
One option to make this happen reliabely (see comments above) is to implement a BHO - esp. the DWebBrowserEvents2::WindowStateChanged
Event is usefull in this scenario.
BHOs are implementations of a bunch of COM interfaces and get loaded into the browser process/each tab... best way to implement them is in C++ IMO.
But it is certainly possible to do so in .NET (although not recommended):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With