/// <summary> /// Creates a new instance of an Internet Explorer browser. /// </summary> /// <returns> An instance of an Internet Explorer browser. </returns> public static Browser Create() { var browser = new InternetExplorer(CreateInternetExplorerClass()); browser.Refresh(); return(browser); }
/// <summary> /// Attempts to attach to an existing browser. /// </summary> /// <returns> An instance of an Internet Explorer browser. </returns> public static Browser Attach() { var foundBrowser = GetBrowserToAttachTo(); if (foundBrowser == null) { return null; } var browser = new InternetExplorer(foundBrowser); browser.Refresh(); return browser; }
/// <summary> /// Attempts to attach to an existing browser. /// </summary> /// <returns> An instance of an Internet Explorer browser. </returns> public static Browser Attach() { var foundBrowser = GetBrowserToAttachTo(); if (foundBrowser == null) { return(null); } var browser = new InternetExplorer(foundBrowser); browser.Refresh(); return(browser); }
/// <summary> /// Attempts to attach to an existing browser. /// </summary> /// <returns> The browser instance or null if not found. </returns> public static Browser Attach(Process process) { if (process.ProcessName != Name) { return(null); } var foundBrowser = GetBrowserToAttachTo(process.Id); if (foundBrowser == null) { return(null); } var browser = new InternetExplorer(foundBrowser); browser.Refresh(); return(browser); }
private static SHDocVw.InternetExplorer GetBrowserToAttachTo(int processId = 0) { var explorers = new ShellWindowsClass() .Cast <SHDocVw.InternetExplorer>() .Where(x => x.FullName.ToLower().Contains("iexplore.exe")) .ToList(); foreach (var explorer in explorers) { try { if (processId > 0) { uint foundProcessId; if (!NativeMethods.GetWindowThreadProcessId(new IntPtr(explorer.HWND), out foundProcessId) || foundProcessId != processId) { continue; } } using (var browser = new InternetExplorer(explorer)) { LogManager.Write($"Found browser with id of {browser.Id} at location {browser.Uri}.", LogLevel.Verbose); } return(explorer); } catch (Exception ex) { // Ignore this browser and move to the next one. LogManager.Write($"Error with finding browser to attach to. Exception: {ex.Message}.", LogLevel.Verbose); } } return(null); }
/// <summary> /// Attempts to attach to an existing browser. /// </summary> /// <returns> The browser instance or null if not found. </returns> public static Browser Attach(Process process) { if (process.ProcessName != BrowserName) { return null; } var foundBrowser = GetBrowserToAttachTo(process.Id); if (foundBrowser == null) { return null; } var browser = new InternetExplorer(foundBrowser); browser.Refresh(); return browser; }
private static SHDocVw.InternetExplorer GetBrowserToAttachTo(int processId = 0) { var explorers = new ShellWindowsClass() .Cast<SHDocVw.InternetExplorer>() .Where(x => x.FullName.ToLower().Contains("iexplore.exe")) .ToList(); foreach (var explorer in explorers) { try { if (processId > 0) { uint foundProcessId; if (!NativeMethods.GetWindowThreadProcessId(new IntPtr(explorer.HWND), out foundProcessId) || (foundProcessId != processId)) { continue; } } using (var browser = new InternetExplorer(explorer)) { //LogManager.Write($"Found browser with id of {browser.Id} at location {browser.Uri}.", LogLevel.Verbose); } return explorer; } catch (Exception) { // Ignore this browser and move to the next one. //LogManager.Write($"Error with finding browser to attach to. Exception: {ex.Message}.", LogLevel.Verbose); } } return null; }
/// <summary> /// Creates a new instance of an Internet Explorer browser. /// </summary> /// <returns> An instance of an Internet Explorer browser. </returns> public static Browser Create() { var browser = new InternetExplorer(CreateInternetExplorerClass()); browser.Refresh(); return browser; }