如何获取新创建的IE8窗口的进程?
当使用.NET的Process.Start运行IE8的iexplore.exe时,如果您已经打开了另一个IE8窗口,那么您刚刚启动的iexplore.exe进程将立即退出,并且其子进程将附加到主IE8进程。这样做的结果是您的 Process 对象将链接到已经退出的“调用者”进程,而不是正在运行的子进程。您想要对 Process 对象执行的任何操作都将导致 InvalidOperationException 告诉您进程已退出。
如何获取链接到实际 IE8 子进程的 Process 对象?
When using .NET's Process.Start to run IE8's iexplore.exe, and if you already have another IE8 window open, then the iexplore.exe process that you just started will immediately exit, and its child process will attach to the main IE8 process. The result of this is your Process object will be linked to the "invoker" process that has already exited, but not the child process that is running. Anything you want to do to the Process object will result in an InvalidOperationException telling you the process has exited.
How do I obtain a Process object that is linked to the actual child IE8 process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为解决方法,您可能需要强制 IE 启动一个新实例(传递
-nomerge
命令行参数):As a workaround you may want to force IE to start a new instance (passing
-nomerge
command line argument):我使用非最佳解决方案来完成此操作 - 在运行 iexplore.exe 之前获取所有 iexplore.exe 进程 ID 的列表,然后在调用 iexplore.exe 后再次获取相同的列表。对两个列表进行比较,额外的 PID 将是我创建的。这当然在某些情况下不起作用(其他应用程序或用户在检测代码运行时启动了额外的 iexplore.exe 进程,或者 IE 作为内部维护任务对进程进行了某种重新排列/重新创建)。
I did it using a non-optimal solution - get a list of all iexplore.exe process IDs before running my iexplore.exe, then get the same list again after iexplore.exe is invoked. Do a diff between the two lists, the extra PID will be the one I've created. This of course won't work in certain cases (other apps or the user started extra iexplore.exe processes while the detection code is running, or IE did some kind of rearrange/recreation of processes as an internal maintenance task).