Windows 7 – Open URL File in New Tab of Existing IE Window from Command Line

command lineinternet-explorer-10tabswindows 7

When IE10 is set as my default browser, double-clicking an internet shortcut (*.url file) opens it in a new tab of the existing IE window. However, when it is not the default, every way of opening a *.url that I've tried brings up a new IE window per file. Is it possible to keep opening files in new tabs of the same IE window when it's not set as the default browser, and how?

What I've tried and it didn't work:

  • "C:\Program Files (x86)\Internet Explorer\iexplore.exe" "C:\Dir1\file.url" (opens a new window every time)

  • C:\Windows\System32\rundll32.exe "C:\Windows\System32\ieframe.dll",OpenURL C:\Dir1\file.url (opens the default browser)

  • classexec "C:\Dir1\file.url" --class htmlFile (using ClassExec utility, opens a new window every time)

I use Windows 7 x64.

Best Answer

PowerShell, adapted from the Shay Levi's answer in Google Groups.

# Set BrowserNavConstants to open URL in new tab
# Full list of BrowserNavConstants: https://msdn.microsoft.com/en-us/library/aa768360.aspx

$navOpenInNewTab = 0x800

# Get running Internet Explorer instances
$App = New-Object -ComObject shell.application

# Grab the last opened tab
$IE = $App.Windows() | Select-Object -Last 1

# Open link in the new tab nearby
$IE.navigate('http://bing.com', $navOpenInNewTab)

# Cleanup
'App', 'IE' | ForEach-Object {Remove-Variable $_ -Force}
Related Question