How to connect to an open Internet explorer window using C #?

Can you use COM / OLE in a C # program to connect to working instances of Internet Explorer?

Ideally, I would like to find the URLs of all the web pages open in IE.

+3
source share
2 answers

I found the answer here , and the code snippet:

public class Form1 : System.Windows.Forms.Form
{
    static private SHDocVw.ShellWindows shellWindows = new
    SHDocVw.ShellWindowsClass();

    public Form1()
    {
       InitializeComponent();    
       foreach(SHDocVw.InternetExplorer ie in shellWindows)
       {
           MessageBox.Show("ie.Location:" + ie.LocationURL);
           ie.BeforeNavigate2 += new
           SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.ie_BeforeNavigate2);
       }
}

 public void ie_BeforeNavigate2(object pDisp , ref object url, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
 {
  MessageBox.Show("event received!");
 } 
}

Does anyone know if the code on this webpage will work with IE 6? I tested it on 7. Thanks!

+3
source
+1
source

Source: https://habr.com/ru/post/1755407/


All Articles