简体   繁体   English

Process.Start(“IEXPLORE.EXE”)在启动后立即触发退出事件..为什么?

[英]Process.Start(“IEXPLORE.EXE”) immediately fires the Exited event after launch.. why?

i have a strange problem with IE8 installed in xp. 我在xp中安装了IE8有一个奇怪的问题。 i was trying to launch IE using an System.Diagnostics.Process.Start method in c#. 我试图使用c#中的System.Diagnostics.Process.Start方法启动IE。 And i have a requirement to trap the exited event of the IE and do some operation. 我需要捕获IE的退出事件并执行一些操作。 But i ended up in a rather strange problem where the IE immediately fires the exited event after launch. 但我最终遇到了一个相当奇怪的问题,IE在发布后立即触发了退出的事件。

this is the sample code 这是示例代码

     Process objProcess = Process.Start("IEXPLORE.EXE", "http://google.com");

     if (objProcess != null)
    {
        objProcess.EnableRaisingEvents = true;
        objProcess.Exited += new EventHandler(myProcess_Exited);        
    }

    public  static void myProcess_Exited(object sender, System.EventArgs e)
    {
        MessageBox.Show("You exited");
    }

But the above code perfectly works when laucnching different process (ex:notepad) and it fires the exit event when i close the exe. 但上面的代码完全适用于laucnching不同的进程(例如:记事本),当我关闭exe时它会触发退出事件。

this only gives problem launching IE 8. Can someone clarify me what is the problem?? 这只会让问题启动IE 8.有人可以澄清我的问题是什么?

UPDATE UPDATE

Most friends replied my post and saying why you can't just use an URL? 大多数朋友回复了我的帖子,并说为什么你不能只使用一个URL? why stick with IE? 为何坚持IE?

here the reason 这里的原因

the ultimate aim of the app is to launch an URL from the windows application and will hide an exe when working on the IE. 该应用程序的最终目的是从Windows应用程序启动URL,并在IE上工作时隐藏exe。 And show the exe after closing the IE. 关闭IE后显示exe。

Thanks 谢谢

Most probably is that you have IE already running as a process, so when you try to launch it again as a new process it looks that there are IE running already, tells it that user initiated a new window (so the initial IE will create a "new" window rather than a new one) and exit. 最有可能的是你已经将IE作为一个进程运行,所以当你尝试再次作为一个新进程启动它时,它看起来已经有IE运行,告诉它用户启动了一个新窗口(所以最初的IE将创建一个“新”窗口而不是新窗口并退出。

Possible solution: try starting the process with "-nomerge" command line option: 可能的解决方案:尝试使用“-nomerge”命令行选项启动该过程:

    Process objProcess = Process.Start("IEXPLORE.EXE", "-nomerge http://google.com/");

Interesting observation : objProcess.ExitCode (for IE8 at least) will be equal to 0 if exited passing control to another instance, and 1 if it was actually closed by user. 有趣的观察objProcess.ExitCode (至少对于IE8)如果退出将控制权传递给另一个实例将等于0 ,如果它实际上被用户关闭则等于1

If another instance of iexplore.exe is already running on the machine, new instances will connect to that and immediately exit. 如果iexplore.exe的另一个实例已在计算机上运行,​​则新实例将连接到该实例并立即退出。 Also, it's possible that even in the case where iexplore is not running, the multiprocess architecture of Internet Explorer 8 has the parent launch child broker process and exit immediately. 此外,即使在iexplore未运行的情况下,Internet Explorer 8的进程体系结构也可能具有父启动子代理进程并立即退出。

But these answers are besides the point. 但这些答案除了重点之外。 You should not be launching Internet Explorer directly. 您不应该直接启动Internet Explorer。 If the user has configured another default browser, they will be unhappy that you are ignoring their preferences. 如果用户配置了另一个默认浏览器,他们会因为忽略了他们的偏好而感到不快。 Instead, why don't you try 相反,你为什么不试试

System.Diagnostics.Process.Start("http://google.com");

directly and that will do the right thing. 直接,这将做正确的事情。 You won't be able to tell when the browser closed, but if the command has opened a new tab in an existing browser session for example, the browser close event will be meaningless to your application. 您将无法判断浏览器何时关闭,但如果该命令在现有浏览器会话中打开了新选项卡,则浏览器关闭事件对您的应用程序将毫无意义。

Maybe IEXPLORE itself launches a different process for the URL and ends the process you created? 也许IEXPLORE本身会为URL启动一个不同的流程并结束您创建的流程? Like a fork on Unix? 像Unix上的fork一样?

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

相关问题 的Process.Start(“IEXPLORE.EXE”); &lt; - 这可靠吗? - Process.Start(“IExplore.exe”); <— Is this reliable? Process.Start("IExplore.exe"); --&gt; System.IO.FileNotFoundException - Process.Start("IExplore.exe"); --> System.IO.FileNotFoundException Process.Start(“ IExplore.exe”,“ http://google.com”)未在VM上启动。 在服务器和本地上工作 - Process.Start(“IExplore.exe”, “http://google.com”) Not Launching On VM. Works on Server and Local C#进程启动firefox.exe在启动后立即触发退出 - C# process start firefox.exe fires the exited immediately after launch Process.Kill似乎不适用于iexplore.exe - Process.Kill does not seem to work with iexplore.exe 如何使用process.start启动setup.exe文件 - How to launch a setup.exe file using process.start IEXPLORE.exe的奇怪的ProcessorAffinity问题 - Strange ProcessorAffinity issue with IEXPLORE.exe c#:是否可以将参数挂接到现有进程。 启动iexplore.exe,然后使其导航到网站的示例 - c# : is it possible to hook arguments to an existing process. Example launching iexplore.exe and then making it to navigate to a website 为什么要Process.Start(“cmd.exe”,进程); 不行? - Why does Process.Start(“cmd.exe”, process); not work? Process.Start将不会启动Chrome - Process.Start will not launch chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM