Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening browser on a variable page using vbscript

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 which works:

Dim objShell

objShell = CreateObject("Shell.Application")
objShell.ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "www.google.ie", "", "", 1)

But I would like to get the following working:

Dim iURL As String
Dim objShell

iURL = "www.google.ie"

objShell = CreateObject("Shell.Application")
objShell.ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", iURL, "", "", 1)

Any ideas what it is I'm doing wrong? Any help would be greatly appreciated.

like image 815
gaynorvader Avatar asked Nov 15 '12 16:11

gaynorvader


People also ask

How do I run a VBScript from a website?

To insert a VBScript into an HTML page, we use the <script> tag. Inside the <script> tag we use the type attribute to define the scripting language. The document. write command is a standard VBScript command for writing output to a page.

Which browser supports VBScript?

VBScript is supported by Internet Explorer of Microsoft only, while other browsers (Firefox and Chrome) offer JavaScript support. Therefore, JavaScript usually is prefered by developers over VBScript. As Internet Explorer (IE) supports VBScript, this feature may be explicitly enabled or disabled.

Can VBScript run on Chrome?

VBScript is supported just by Microsoft's Internet Explorer while other browsers (Firefox and Chrome) support just JavaScript. Hence, developers normally prefer JavaScript over VBScript.


2 Answers

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)
like image 97
Alex K. Avatar answered Sep 18 '22 01:09

Alex K.


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}"
like image 44
secretname Avatar answered Sep 18 '22 01:09

secretname