Internet Explorer BHO check for multi-instance of site

放肆的年华 提交于 2019-12-11 23:49:01

问题


I'm working on a project for a client. We are building an internal web portal, and for various (mostly political) reasons have ended up building a BHO for IE8. One of the things t does is make sur that only one instance of the portal can be opened at once. It does this by writing a temp file when the portal is opened. Unfortunately this is not optimal as if IE crashes for any reason then the next time the portal is fired up, the user is left staring at an "unauthorised" message until the stale temp file is removed. So my question is: is there any way within a BHO to see how many times the same url has been loaded? I mean is there some way to get that information directly from IE? It's actually a little more complicated than that, given that we need to allow popups etc. But this would be a good start.

Thanks for your time.


回答1:


If you want limit browser instances in the current user session you can use a mutex instead of a file. try acquire the mutex at the startup of the BHO (in the SetSite call) with a reasonable timeout, and release again in the final SetSite call.

If the result is WAIT_OBJECT_0 or WAIT_ABANDONED, there is no other BHO instance holding the mutex, while WAIT_ABANDONED occur when another thread crashed while holding the mutex. If the result is WAIT_TIMEOUT, the mutex is already taken by another BHO instance and you should not let the user to use your web site according to your requirement.

But if I am a determined user I can fire up XP Mode and access the web site from there...



来源:https://stackoverflow.com/questions/5731396/internet-explorer-bho-check-for-multi-instance-of-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!