使用shdocvw库(添加对它的引用,你可以在windows\system32中找到它)可以获取实例列表,并使用newtab参数调用navigate:
ShellWindows iExplorerInstances = new ShellWindows();
if (iExplorerInstances.Count > 0)
{
IEnumerator enumerator = iExplorerInstances.GetEnumerator();
enumerator.MoveNext();
InternetExplorer iExplorer = (InternetExplorer)enumerator.Current;
iExplorer.Navigate(url, 0x800);
}
else
{
}
编辑:在某些情况下,您可能需要检查shell窗口是否对应于真正的iexplorer而不是任何其他Windows shell(在w7中返回所有实例,现在不知道其他情况)。
编辑注释:在某些情况下,您需要检查Shell窗口是否对应于真正的Internet Explorer浏览器,而不是任何其他Windows壳程序。在Windows 7中,所有实例都会被返回,但其他版本可能会有所不同。
bool found=false;
foreach (InternetExplorer iExplorer in iExplorerInstances)
{
if (iExplorer.Name == "Windows Internet Explorer")
{
iExplorer.Navigate(ur, 0x800);
found=true;
break;
}
}
if(!found)
{
}
你可能会发现这些额外的IE Navigate标志也很有用。 标志的完整描述可在http://msdn.microsoft.com/en-us/library/dd565688(v=vs.85).aspx找到。
enum BrowserNavConstants
{
navOpenInNewWindow = 0x1,
navNoHistory = 0x2,
navNoReadFromCache = 0x4,
navNoWriteToCache = 0x8,
navAllowAutosearch = 0x10,
navBrowserBar = 0x20,
navHyperlink = 0x40,
navEnforceRestricted = 0x80,
navNewWindowsManaged = 0x0100,
navUntrustedForDownload = 0x0200,
navTrustedForActiveX = 0x0400,
navOpenInNewTab = 0x0800,
navOpenInBackgroundTab = 0x1000,
navKeepWordWheelText = 0x2000,
navVirtualTab = 0x4000,
navBlockRedirectsXDomain = 0x8000,
navOpenNewForegroundTab = 0x10000
};