Sunday, 29 July 2018

Open a URL file in a new tab of existing IE window from command line


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.



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}

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...