2011-05-02 41 views
0

我想使用mshtml(c#代碼)關閉新打開的Internet Explorer窗口。 我使用了帶有Ie實例的Mshtml,並通過一個URL導航並單擊了一個鏈接。一旦我點擊鏈接,我就會在新窗口中打開文檔。我想知道有沒有辦法從新打開的窗口和獲取的值,關閉窗口後獲取的值..如何使用mshtml(c#代碼)關閉新打開的Internet Explorer

在此先感謝....

烏尼

回答

1

見下面的代碼...

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

獎勵用於清理(ReleaseComObject的) – 2013-02-12 18:23:32

+0

這很有趣的'quit'方法是如何在[文檔]的例子之一(使用https://msdn.microsoft.com /en-us/library/aa752084.aspx),但它不出現在可用方法的列表中。 – GetFree 2015-03-02 21:19:47

相關問題