Unni Krishnan
Unni Krishnan

Reputation: 94

How can I close the newly opened Internet Explorer using the mshtml

I want to close a newly opened Internet Explorer using the mshtml.

I have a program , which takes values from different IE Window. The navigation to each Window is invoked using the Click() method of element. Once process the page, I want to close the Window.

Any one know how to close the window using the Mshtml.

thanks in advance Unni

Upvotes: 1

Views: 236

Answers (2)

A.A. Hendriksen
A.A. Hendriksen

Reputation: 31

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. 
}

Upvotes: 1

MSalters
MSalters

Reputation: 179779

Easy: Get the HWND from IWebBrowser2, and send it a WM_CLOSE.

Upvotes: 0

Related Questions