开发者

IE.navigate2 fails with protected mode off

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?


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


Getting InternetExplorer.ApplicationMedium by CLSID:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜