1

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
  • `Shell()` is not a built-in VBScript function, you're missing a custom function call `Shell()` that probably encapsulates the `WshShell` object `Run()` method. – user692942 Mar 02 '22 at 18:06
  • Are you open to using Powershell instead? – Joel Coehoorn Mar 02 '22 at 18:07
  • @JoelCoehoorn what is wrong with using VBScript, it will absolutely work for this? – user692942 Mar 02 '22 at 18:08
  • Does this answer your question? [Opening browser on a variable page using vbscript](https://stackoverflow.com/questions/13401749/opening-browser-on-a-variable-page-using-vbscript) – user692942 Mar 02 '22 at 19:04
  • @JoelCoehoorn we tried PowerShell, but we were using a 3rd party tool to position the window and because the pid changes we cannot call out each separate browser window. I'd love to post that script as well, I will try and post that into the main post, dont know how successful I will be. But basically what it comes down to is we want specific URLS to open up on specific screens. Its a computer with 8 monitors distributed through video over ethernet. I dont care how it gets done, but need to get it done as IE is going away. – Robert Wisneski Mar 02 '22 at 20:11
  • @user692942 Possibly, let me try it out. – Robert Wisneski Mar 02 '22 at 20:23
  • @JoelCoehoorn I did get the script posted to the original. To be clear, that script may be not workable right now as we were playing around with it. Our Powershell guy was trying to make it work, not sure where he left off on it. In PS, we can get it to work, but it opens up on one window and we couldnt get it move positions except for one monitor. – Robert Wisneski Mar 02 '22 at 20:25
  • @RobertWisneski have you tried using `--window-size` and `--window-postion` as additional arguments for edge (like in your Powershell script)? – Shrotter Mar 03 '22 at 07:23

1 Answers1

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.

LesFerch
  • 1,540
  • 2
  • 5
  • 21
  • Actually, Windows 11 does include IE. If you look for `iexplore.exe` it’s still there. Proved this the other day with a work colleague who’s running Windows 11. – user692942 Mar 03 '22 at 05:22
  • Also, the OP wasn’t asking to use `InternetExplorer.Application` they realise that wasn’t an option the script they are trying to use is using `WScript.Shell` to execute the executable. – user692942 Mar 03 '22 at 05:25
  • It actually looks as though `iexplore.exe` opens Edge but in IE mode, my mistake. – user692942 Mar 03 '22 at 09:00
  • 1
    @user692942 Actually, you were correct about IE still being in Windows 11. It's fully functional, with IE COM automation, as long as you have Window 11 build `22000.348` or higher. The only part of IE that is gone is the ability for a user to launch it easily as their Internet browser. – LesFerch Apr 18 '22 at 05:39