'Moving away from IE and into edge
I have a VBS script that works great with Internet Explorer. It opens Internet Explorer in kiosk mode on multiple monitors. I have been trying to change it to launch Edge with very little success.
Here is the basic script that doesnt work.
I changed the sub launchIE to Edge, but getting type mismatch 'Shell'
What works with IE is this code.
Sub launchIE
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.navigate strURL
set WshShell = CreateObject("WScript.Shell")
'wshShell.exec "c:\nomousy.exe /hide"
strRes = 0
strUrl = "http://WWW.CNN.COM"
launchIE
strRes = strRes + 1280
strUrl = "http://www.Foxnews.com"
launchIE
strRes = strRes + 1280
strUrl = "http://www.StackOverflow.com"
launchIE
WScript.quit
Sub launchIE
Set objExplorer = CreateObject("Shell.Application")
Call Shell ("msedge.exe")
objExplorer.navigate strURL
objExplorer.Left = strRes
objExplorer.Top = 0
objExplorer.Visible = True
objExplorer.FullScreen = True
objExplorer.StatusBar = 0
End Sub
Do
' Wait till the Browser is loaded
Loop Until objExplorer.readyState = 4
Powershell Script
#Community-developed module to support setting a window location with x & y coordinates
Import-Module C:\temp\Set-Window.psm1
#Get information about all locally attached monitors
Add-Type -AssemblyName System.Windows.Forms
$AllDisplays = [System.Windows.Forms.Screen]::AllScreens
#Kill all Edge processes; we need to make sure no Edge instances are running in the background before starting
Get-Process -Name msedge -ErrorAction SilentlyContinue | Stop-Process -Force
#List of urls
if ($env:computername -eq "Window8680"){
$testURLs = @(
"http://www.foxnews.com",
"http://www.cnn.com",
"http://www.stackoverflow.com",
)
#} elseif ($env:computername -eq "Windows1068"){
} else {
#Start-Process -FilePath C:\Temp\nomousy.exe -ArgumentList "/hide" -PassThru
$testURLs = @(
"http://www.foxnews.com",
"http://www.cnn.com",
"http://www.stackoverflow.com",
)
}
#Set x coordinates
$X = 0
#Null array to hold main window titles
$HandledIDs = @()
#Loop through urls
foreach($URL in $testURLs){
#Start MSEdge
Start-Process -FilePath "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -ArgumentList "--new-window --start-fullscreen $URL"
Start-Sleep -Seconds 2
pause
#Get the PID of the relevant process.
#$EdgeID = Get-Process -Name MSEdge | Where {$_.MainWindowTitle.length -ge 1 -and $_.ID -notin $HandledIDs} | Select -ExpandProperty ID
#$HandledIDs += $EdgeID
#Set window location
#"Attempting to set PID $EdgeID to X coordinate $($AllDisplays[$X].WorkingArea.X)"
#Set-Window -ID $EdgeID -X $($AllDisplays[$X].WorkingArea.X) -Verbose
#$X = $X + 1
Solution 1:[1]
If you are concerned about migrating your script to Windows 11, you don't need to change anything, but you will need Windows 11 build 22000.348 or higher to use the IE COM object.
However, if you wish to load each URL in Edge instead of IE for reasons of web page compatibility (e.g. stackoverflow.com does not work in IE) then you can use the Run method to launch each URL in Edge, but you won't be able to control the web page as you can with IE. Here's an example:
set oWSH = CreateObject("WScript.Shell")
LaunchEdge "www.cnn.com",false
LaunchEdge "www.foxnews.com",false
LaunchEdge "www.yahoo.com",false
WScript.Quit
Sub LaunchEdge(URL,NewWindow)
Param = ""
If NewWindow Then Param = "--new-window"
oWSH.Run "msedge.exe """ & Param & " " & URL & """",0,False
End Sub
Other options:
Use the Selenium WebDriver with VBScript
Write a C# program using WebView2.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
