How can I close the newly opened Internet Explorer using the mshtml (c# code)

3.2k Views Asked by At

I want to close a newly opened internet Explorer window using the mshtml (c# code). I used the Mshtml with the instance of Ie and navigated through a url and clicked on a link. Once i click the link , i am getting the document opened in a new window. I want to know is there any way to fetch the values from the newly opened window and after getting the values to close the window..

Thanks in advance....

Unni

1

There are 1 best solutions below

2
On

See the following code...

using System.Runtime.InteropServices;
// IE can be found in COM library called 
// Microsoft Internet Controls: 
using IE = SHDocVw.InternetExplorer; 
static void OpenAndCloseIE()
{
    // Get an instance of Internet Explorer: 
    Type objClassType = Type.GetTypeFromProgID("InternetExplorer.Application");
    var instance = Activator.CreateInstance(objClassType) as IE;

    // Close Internet Explorer again: 
    instance.Quit();

    // Release instance: 
    System.Runtime.InteropServices.Marshal.ReleaseComObject(instance);
    instance = null; // Don't forget to unreference it. 
}