I start a process in c# like this:
Process p= new Process();
p.StartInfo.FileName = "iexplore.exe";
p.StartInfo.Arguments = "about:blank";
p.Start();
Sometimes I already have an instance of Internet Explorer running (something I cannot control), and when I try to grab the MainWindowHandle of p:
p.MainWindowHandle
I get an exception, saying the process has already exited.
I am trying to get the MainwindowHandle so I can attach it to an InternetExplorer object.
How can I accomplish this with multiple instances of IE running?
Process.MainWindowHandle does only raise an exception, if the process has not been started yet or has already been closed.
So you have to catch the exception is this cases.