获取 SHDocVw.InternetExplorer 生成的 IE8 进程的进程 ID

发布于 2024-11-30 14:21:24 字数 1237 浏览 1 评论 0原文

我正在使用 SHDocVw.InternetExplorer 启动我的代码中的IE。在某些情况下,InternetExplorer.Quit() 不起作用。我尝试了几件事来使退出工作,但是没有成功。我现在求助于 Process.Kill。

现在,如果在使用 SHDocVw.InternetExplorer 启动另一个手动启动的 IE8 实例时已经在运行,则新实例将创建为现有 IE 的子进程:

SHDocVw.InternetExplorer 生成的 IE 是现有 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:

SHDocVw.InternetExplorer spawned IE is a child 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文