IE.navigate2 fails with protected mode off

寵の児 提交于 2019-12-09 07:36:25

问题


I'm automating IE8 from Excel VBA (Excel 2010, Windows 7)

Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate2 URL

If URL is a website in a zone where IE protected mode is on, everything is fine.

If URL is a website in a zone where IE protected mode is off, the script fails (IE becomes automatically visible, IE object is lost in VBA - automation error).

Is there any way to enable navigate2 in zones with protected mode off?


回答1:


What you want to do is create an instance of IE running at Medium Integrity, and navigate that. Typically, you'd do that by using CoCreateInstance(CLSID_InternetExplorerMedium). Currently, there's no ProgID that points at this CLSID, however, it you can easily create one:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\InternetExplorer.ApplicationMedium]

[HKEY_CLASSES_ROOT\InternetExplorer.ApplicationMedium\CLSID]
@="{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}"

You can then invoke this object thusly:

CreateObject("InternetExplorer.ApplicationMedium")

I explain a bit more fully over here: http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx




回答2:


Getting InternetExplorer.ApplicationMedium by CLSID:

Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")


来源:https://stackoverflow.com/questions/6909226/ie-navigate2-fails-with-protected-mode-off

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