如何关闭Internet Explorer时,它已经跑了的Process.Start? [英] How to close Internet Explorer when it has been ran with Process.Start?

查看:633
本文介绍了如何关闭Internet Explorer时,它已经跑了的Process.Start?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个启动Internet Explorer中的WPF应用程序中使用的Process.Start 方法(第9版,Win7上X64)。

I'm have a WPF application that is starting Internet explorer (Version 9, on Win7 X64) using Process.Start method.

我保存的ProcessID,以关闭它,当应用程序被关闭。然而,当应用程序退出时,Internet Explorer仍然是在任务管理器中可见

I save the ProcessID in order to close it when the application is closed. However, when the application exits, the Internet Explorer is still visible in the task manager.

下面是我使用的代码:

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();
        }
    }
}



}

}

我仔细检查了,调用 _process.Close()实际上是完成的。

I double checked, the call to _process.Close() is actually done.

什么可能导致此行为

PS:我怀疑这是由于Internet Explorer的内部。运行exe将没有必要创建新的进程,但可以使用一些工控机控制其它实例。我用的是 -noframemerging 命令行参数,但它看起来不解决这个问题。

PS: I'm suspecting this is due to Internet Explorer internal. Running the exe won't necessary create a new process, but can use some IPC to control other instances. I use the -noframemerging command line argument, but it does not look to solve the issue.

这是另一个问题,我问前几天的延续。事实上,我Pinvoking SetParent函数embbed衍生的IE浏览器在我的应用程序。我不能使用WebBrowser控件,因为它不支持我要找的隔离。所以这是确定,关闭IE浏览器时,我的应用程序关闭。

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. I can't use the WebBrowser control because it does not support the isolation I'm looking for. So it's OK to close IE when my app closes.

推荐答案

我在我的Win32应用程序的IE浏览器的应用程序,我使用的Win32API - SendMessage函数与WM_CLOSE = 0×0010

I have an IE application in my win32 Application and i'm using Win32Api - SendMessage with WM_CLOSE = 0x0010

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

这将关闭IE浏览器,你需要怎么过有浏览器(类IEFrame)的具体处理。

This closes the IE, how ever you need to have the specific handle of the Browser (Class IEFrame).

有一个缺点,如果你有一个以上的标签,将IE浏览器打开确认关闭对话框,防止关闭过程。

There is one drawback, in case you have more then one tab, the IE opens confirm close dialog which prevent the close process.

要克服对话开幕一种方法是将其设置复选框(始终紧贴),但对我来说ITTS不是一个选项。

One way to overcome the dialog opening is to set it check box to (always close), but for me itţs not an option.

这篇关于如何关闭Internet Explorer时,它已经跑了的Process.Start?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆