使用 shdocvw 库(添加对其的引用,您可以在 windows\system32 中找到它),您可以获取实例列表并使用 newtab 参数调用导航:
ShellWindows iExplorerInstances = new ShellWindows();
if (iExplorerInstances.Count > 0)
{
IEnumerator enumerator = iExplorerInstances.GetEnumerator();
enumerator.MoveNext();
InternetExplorer iExplorer = (InternetExplorer)enumerator.Current;
iExplorer.Navigate(url, 0x800); //0x800 means new tab
}
else
{
//No iexplore running, use your processinfo method
}
编辑:在某些情况下,您可能必须检查 shellwindow 是否对应于真正的 iexplorer,而不是任何其他 Windows shell(在 w7 中返回所有实例,现在不知道其他实例)。
bool found=false;
foreach (InternetExplorer iExplorer in iExplorerInstances)
{
if (iExplorer.Name == "Windows Internet Explorer")
{
iExplorer.Navigate(ur, 0x800);
found=true;
break;
}
}
if(!found)
{
//run with processinfo
}
您可能还会发现这些额外的 IE 导航标志很有用。标志的完整描述可在http://msdn.microsoft.com/en-us/library/dd565688(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/dd565688%28v=vs.85%29.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
};