Launch URLs in Internet Explorer Tabs

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dwa2005
Posts: 3
Last visit: Thu Oct 20, 2022 6:19 am

Launch URLs in Internet Explorer Tabs

Post by dwa2005 »

I have been trying for sometime to launch URLs in tabs within Internet Explorer. While I have been successful, it fails more times that succeeds. The error message is always the same: The interface is unknown. (Exception from HRESULT: 0X800706B5). I can always get the first item to launch, but it always seems to fail at the second or third item. The items are an array built from a semi-colon separated list. My code is below.

Any assistance will be greatly appreciated.

____

$CurrentURLsArray = $CurrentURLs.Split(";")
$navOpenInBackgroundTab = 0x1000;
$ie = new-object -com InternetExplorer.Application
$ie.Visible = $true;
foreach ($item in $CurrentURLsArray)
{
Try
{
if ($item -eq $CurrentURLsArray[0]) { $ie.Navigate2($item); }
Else
{
$ie.Navigate2($item, $navOpenInBackgroundTab);
}
}
Catch
{
$FailedApps = 1
$ErrorMessage = $_.Exception.Message

"Failed to launch URL - $item" | Out-File $LogFile -Append
"Error Message: $ErrorMessage" | Out-File $LogFile -Append
}

}


____



Product, version and build: Powershell Studio 2018 5.5.153
32 or 64 bit version of product: 64-bit
Operating system:
32 or 64 bit OS: 64-bit
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Launch URLs in Internet Explorer Tabs

Post by davidc »

[TOPIC MOVED TO WINDOWS POWERSHELL FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Launch URLs in Internet Explorer Tabs

Post by jvierra »

Note the message on the top of this page: "Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file."

You have to wait until the page loads before specifying a new page.

While($ie.Busy){sleep 1}

Also IE will not cause an exception on a failed navigate. "Try/Catch" is not very useful here. If you are getting exceptions then there is some other issue with you browser.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked