开发者

How to get job handle if I have HANDLE to one of the windows of the job

开发者 https://www.devze.com 2023-01-06 18:27 出处:网络
My application tried to scrape IE8, here we somehow obtain HANDLE to Internet Explorer Window/UI. Now I want to get the job handle for IE8.

My application tried to scrape IE8, here we somehow obtain HANDLE to Internet Explorer Window/UI. Now I want to get the job handle for IE8. One Idea is to - Determine first the process id using the IE Window HANDLE using GetWindowThreadProcessId() but after this I am stuck.

There is new implementation in IE8, here every tab opened is a process within a job. Thus IE8 we see is ma开发者_如何学Gonaged as a job.


I couldn't find any documented way to get the job to which a process is bound; also, I couldn't find any documented way to enumerate all the jobs in the system, except the WMI way that however works only from XP onwards (which I don't think it's a problem since you're targeting IE8) and only with named jobs (which may actually be a problem if IE8 uses anonymous job objects).

If IE's jobs are in this list, then the road is downhill: just use OpenJobObject on each job name you can get (or, if you manage to narrow down your work with some heuristic on the job names, even better) and use the IsProcessInJob to check if your process handle (which you get with OpenProcess + GetWindowThreadProcessId) belongs to the job; once you get a match, you're set. Remember to close all those handles! :)

In the unfortunate event that the job objects used by IE8 are unnamed, then the whole thing becomes more difficult. You probably need to resort to almost-undocumented (by Microsoft, but widely documented on the net) handle-enumeration techniques to enumerate all the handles relative to your target process. You can then filter out just the job objects handles, and use the technique described above to get the right one.


By the way, why do you need to access the job objects used by IE8?

0

精彩评论

暂无评论...
验证码 换一张
取 消