Opening a hidden Internet Explorer window without its focus?

I want to open a hidden Internet Explorer window without stealing focus. I have a Timer object that opens Internet Explorer every 5 minutes to check the site for updates. The problem is that every time he checks for updates, he intercepts the focus from the current application in the foreground. The following is a way to start the process:

Process m_Proc = new Process(); m_Proc.StartInfo.Arguments = String.Format("{0}{1}", "-nomerge ", browserURL); m_Proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; m_Proc.StartInfo.UseShellExecute = true; m_Proc.StartInfo.CreateNoWindow = true; m_Proc.StartInfo.FileName = String.Format("iexplore.exe"); m_Proc.Start(); 

He always steals focus, even when he is hidden. I want it to start as if nothing was happening, so users can continue to work on what they are doing. Thanks.

+4
source share
2 answers

Try automating Internet Explorer through your COM interfaces, rather than creating a process explicitly. Here's how to do it. Just do not do ie.Visible = true and it will remain hidden. Call ie.Quit() when you ie.Quit() done with it.

+1
source

I'm not even sure why you open a browser for this, isn’t it easier for your code to simply check the site in another way? Maybe something like this.

  string url = "http://www.google.com"; string result = null; try { WebClient client = new WebClient(); result = client.DownloadString(url); //Store this result and compare it to last stored result for changes. } catch (Exception ex) { // handle error MessageBox.Show(ex.Message); } 

My C # is rusty, so you need to double check this.

0
source

All Articles