获取 SHDocVw.InternetExplorer 生成的 IE8 进程的进程 ID
我正在使用 SHDocVw.InternetExplorer 启动我的代码中的IE。在某些情况下,InternetExplorer.Quit() 不起作用。我尝试了几件事来使退出工作,但是没有成功。我现在求助于 Process.Kill。
现在,如果在使用 SHDocVw.InternetExplorer 启动另一个手动启动的 IE8 实例时已经在运行,则新实例将创建为现有 IE 的子进程:
屏幕截图上的 SHDocVw.InternetExplorer IE 的进程 ID 为 996,手动启动的一个是 3388 加上它的子 2876。
现在如果我使用 InternetExplorer.HWND 检索 IE 的窗口句柄,然后 GetWindowThreadProcessId 获取进程 ID 我最终得到 3388 ,当我想要的是996时,InternetExplorer.HWND启动的IE进程ID为父IE进程ID。
我不确定哪一步出错了。
我应该以不同的方式检索 HWND 还是进程 ID?或者两者兼而有之?
谢谢!
编辑:我刚刚尝试向 HWND 发送 WM_CLOSE
,它关闭了父 IE。我想这意味着我得到了错误的 HWND?
编辑:值得注意的是,当我关闭时,只有手动启动的 IE 可见。这是否意味着我将获得唯一可见 IE 的 HWND?
I'm using SHDocVw.InternetExplorer to launch IE in my code. In certain cases InternetExplorer.Quit() doesn't work. I have tried several things to make Quit work but without success. I'm now resorting to Process.Kill.
Now if a manually launched instance of IE8 is already running when SHDocVw.InternetExplorer is used to launch another one the new one gets created as a child process of the existing IE:
The SHDocVw.InternetExplorer IE is process id 996 on the screenshot, the manually launched one is 3388 plus its child 2876.
Now if I use InternetExplorer.HWND to retrieve the window handle of my IE and then GetWindowThreadProcessId to get the process ID I end up with 3388, the parent IE process ID when what I want is 996, the InternetExplorer.HWND launched IE process ID.
I'm not sure on which step it gets wrong.
Should I be retrieving the HWND in a different way or the process ID? Or both?
Thanks!
Edit: I've just tried sending WM_CLOSE
to the HWND and it closed the parent IE. I suppose it means I'm getting a wrong HWND?
Edit: It may be worth noting that only the manually launched IE is visible when I do the closing. Would this mean I'm getting the HWND of the only visible IE therefore?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论