I\'m trying to write a bit of VBScript to open a browser on a specific webpage. Ultimately this webpage would be unique per script. At the moment I have the following code w
No As String
as VBScript is not strongly type, you need a set
when you create an instance of the COM object & no parens around the method call;
Dim iURL
Dim objShell
iURL = "www.google.ie"
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "chrome.exe", iURL, "", "", 1
Or if chrome is the default
set objShell = CreateObject("WScript.Shell")
objShell.run(iURL)
Sub RickRoller()
Dim counter, myNum, objShell, iURL
counter = 0
myNum = 100
Do Until myNum = 1
myNum = myNum - 1
counter = counter + 1
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAF))
Loop
set objShell = CreateObject("WScript.Shell")
iURL = "https://youtu.be/oHg5SJYRHA0?autoplay=1&t=44"
objShell.run(iURL)
End Sub
RickRoller()
Can you pl insert "Call" prefix to "objShell.ShellExecute"
Dim objShell
Set objShell = CreateObject("Shell.Application")
iURL = "www.google.com"
Call objShell.ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", iURL, "", "", 1)
For IE:
'Call objShell.ShellExecute("iexplore.exe", iURL, "", "", 1)
For more info below code also works,
Dim objShell
Set objShell = CreateObject("Shell.Application")
chrome:
iURL = "www.google.com"
'objShell.ShellExecute "chrome.exe", iURL, "", "", 1
ie:
'objShell.ShellExecute "iexplore.exe", iURL, "", "", 1
I found the easiest way is to do this:
set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.run "chrome.exe"
WScript.sleep 400
WshShell.sendkeys "URL HERE"
WshShell.sendkeys "{ENTER}"
also just a fyi you can do this to close chrome:
WshShell.sendkeys "%{F4}"