简体   繁体   English

使用Process.Start运行Internet Explorer后如何关闭它?

[英]How to close Internet Explorer when it has been ran with Process.Start?

I'm have a WPF application that is starting Internet explorer (Version 9, on Win7 X64) using Process.Start method. 我有一个WPF应用程序,正在使用Process.Start方法启动Internet Explorer(Win7 X64上的版本9)。

I save the ProcessID in order to close it when the application is closed. 我保存ProcessID以便在应用程序关闭时将其关闭。 However, when the application exits, the Internet Explorer is still visible in the task manager. 但是,当应用程序退出时,Internet Explorer在任务管理器中仍然可见。

Here is the code I'm using : 这是我正在使用的代码:

public class MyClass : IDisposable
{
    Process _process;


    public void Go()
    {

        ProcessStartInfo psi = new ProcessStartInfo { 
            FileName = "iexplore.exe", 
            Arguments = "-noframemerging -private \"http://whathaveyoutried.com\"" 
        };
        _process = Process.Start(psi);
        _process.WaitForInputIdle();
    }

    private void Close(object sender, RoutedEventArgs e)
    {
        if (_process != null)
        {
            _process.Refresh();
            _process.Close();
        }
    }

    public void Dispose()
    {
        if (_process != null)
        {
            _process.Refresh();
            _process.Close();
        }
    }
}

} }

I double checked, the call to _process.Close() is actually done. 我仔细检查过,对_process.Close()的调用实际上已经完成。

What can cause this behavior? 什么会导致这种行为?

PS: I'm suspecting this is due to Internet Explorer internal. PS:我怀疑这是由于Internet Explorer内部造成的。 Running the exe won't necessary create a new process, but can use some IPC to control other instances. 运行exe不需要创建新进程,但是可以使用某些IPC来控制其他实例。 I use the -noframemerging command line argument, but it does not look to solve the issue. 我使用-noframemerging命令行参数,但是它看起来并不能解决问题。

[Edit] This is the continuation of another question I asked few days ago . [编辑]这是我几天前问的另一个问题的延续。 Actually, I'm Pinvoking SetParent function to embbed the spawned IE in my application. 实际上,我正在使用Pinvoking SetParent函数将生成的IE嵌入我的应用程序中。 I can't use the WebBrowser control because it does not support the isolation I'm looking for. 我不能使用WebBrowser控件,因为它不支持我正在寻找的隔离。 So it's OK to close IE when my app closes. 因此,当我的应用关闭时,可以关闭IE。

Every tab of Internet Explorer is a process. Internet Explorer的每个选项卡都是一个过程。 If you open IE with multiple tabs or user opens another tabs, it won't be enough to kill process. 如果您打开带有多个选项卡的IE或用户打开另一个选项卡,则不足以杀死进程。

But

_process.Close();

Frees all resources belongs to _process. 释放属于_process的所有资源。 You can use _process.Kill() method instead of it. 您可以使用_process.Kill()方法代替它。

For better security and stability, IE8 uses the Loosely Coupled Internet Explorer (LCIE) architecture and runs the browser frame and tabs in separate processes. 为了获得更好的安全性和稳定性,IE8使用松耦合Internet Explorer(LCIE)架构,并在单独的进程中运行浏览器框架和选项卡。 LCIE prevents glitches and hangs from bringing down the entire browser and leads to higher performance and scalability. LCIE可以防止故障和死机导致整个浏览器崩溃,并提高性能和可伸缩性。 I read this on Wikipedia . 我在Wikipedia上阅读过此内容

You can disable LCIE , but I am not sure why you would want to do that. 您可以禁用LCIE ,但是我不确定为什么要这么做。 I would consider using the a solution that @Damien_The_Unbeliever mention above. 我会考虑使用@Damien_The_Unbeliever上面提到的解决方案。

I have an IE application in my win32 Application and i'm using Win32Api - SendMessage with WM_CLOSE = 0x0010 我的win32应用程序中有一个IE应用程序,并且我正在使用Win32Api - SendMessage with WM_CLOSE = 0x0010

SendMessage(handle,0x0010,IntPtr.Zero, IntPtr.Zero)}

This closes the IE, how ever you need to have the specific handle of the Browser (Class IEFrame). 这将关闭IE,即您需要具有浏览器的特定句柄(类IEFrame)的方式。

There is one drawback, in case you have more then one tab, the IE opens confirm close dialog which prevent the close process. 有一个缺点,如果您有多个选项卡,则IE将打开“确认关闭”对话框,从而阻止关闭过程。

One way to overcome the dialog opening is to set it check box to (always close), but for me itţs not an option. 解决对话框打开问题的一种方法是将其复选框设置为(始终关闭),但对我来说这不是一个选择。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Process.Start 打开资源管理器 - Process.Start opening explorer 使用 Process.Start 打开资源管理器 - Using Process.Start to open explorer 在 CMD Works 中运行脚本但在 C# python 脚本中使用 Process.Start() 运行时失败 - Running Script in CMD Works but when ran using Process.Start() in C# python script fails 如何使用带有用户名和密码的 Process.Start 方法在文件资源管理器上打开共享文件夹 - How to open a Shared Folder on the File Explorer using Process.Start Method with userName and Password Process.Start()的可靠性,然后使用C#关闭当前进程 - Reliability of Process.Start() then close current process by using C# 当我使用 Process.Start(“explorer.exe”, path); - windows explorer is opening behind of my wpf application when i used Process.Start(“explorer.exe”, path); 硒如何关闭Internet Explorer已停止工作 - Selenium how to close Internet Explorer has stopped working Process.Start()何时可以返回null? - When can Process.Start() return null? 使用 mingw32 的批处理文件将在资源管理器中手动启动,但在使用 Process.Start() 时立即关闭 C# - Batch file that utilizes mingw32 will start manually in Explorer, but immediately closes when using Process.Start() C# 如何确保由Process.Start(ProcessStartInfo)启动的进程窗口具有所有窗体的焦点? - How to ensure process window launched by Process.Start(ProcessStartInfo) has focus of all Forms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM