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 navigati开发者_高级运维on 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
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.
}
Easy: Get the HWND
from IWebBrowser2
, and send it a WM_CLOSE
.
精彩评论