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:
- 4824 - - iexplore
- 3208 - - iexplore
- 4864 - Google - Windows Internet Explorer - iexplore
Next run (with the other IE window selected beforehand):
- 4824 - - iexplore
- 3208 - - iexplore
- 4864 - id Software - Windows Internet Explorer - iexplore
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?