【问题标题】:Com error when trying to auto close browser sometimes有时尝试自动关闭浏览器时出现 Com 错误
【发布时间】:2010-09-28 16:15:41
【问题描述】:

我尝试使用以下代码在 C# 中关闭我的浏览器:

private void KillIE()
    {
        ShellWindows winShells = new ShellWindowsClass();
        foreach (InternetExplorer Browser in winShells )
        {
            Browser.Quit();
        }
    }

有时它的工作,但今天它没有,我无法让它工作。现在我得到的只是以下消息。

对 COM 组件的调用返回了错误 HRESULT E_FAIL。

有人知道为什么会这样吗?

【问题讨论】:

    标签: c# internet-explorer com


    【解决方案1】:

    使用Process 类可能是一种解决方法,而且绝对是“.NET 方式”。

    using System.Diagnostics;
    
    foreach (Process proc In Process.GetProcessesByName("iexplorer.exe"))
    {
        // The nice way
        proc.CloseMainWindow();
    
        // The hard way
        proc.Kill();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-06
      • 2017-05-15
      • 2022-08-11
      • 2012-04-21
      • 1970-01-01
      • 2020-10-05
      • 2023-04-02
      • 2017-10-27
      相关资源
      最近更新 更多