IE.navigate2 fails with protected mode off

2019-03-21 16:35发布

问题:

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}")