使用vbscript在变量页面上打开浏览器

时间:2012-11-15 16:21:01

标签: browser vbscript

我正在尝试编写一些VBScript来打开特定网页上的浏览器。最终,这个网页对每个脚本都是唯一的。目前我有以下代码可用:

Dim objShell

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

但我希望以下工作:

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)

任何想法是什么我做错了?任何帮助将不胜感激。

4 个答案:

答案 0 :(得分:8)

As String因为VBScript不是强类型,所以在创建COM对象的实例时需要set。方法调用周围没有任何问题;

Dim iURL 
Dim objShell

iURL = "www.google.ie"

set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "chrome.exe", iURL, "", "", 1

或者,如果chrome是默认

set objShell = CreateObject("WScript.Shell")
objShell.run(iURL)

答案 1 :(得分:1)

您可以将“Call”前缀插入“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)

对于IE:

'Call objShell.ShellExecute("iexplore.exe", iURL, "", "", 1)


For more info below code also works,

Dim objShell
Set objShell = CreateObject("Shell.Application")

铬:

iURL = "www.google.com"
'objShell.ShellExecute "chrome.exe", iURL, "", "", 1

即:

'objShell.ShellExecute "iexplore.exe", iURL, "", "", 1

答案 2 :(得分:1)

我发现最简单的方法就是这样做:

set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.run "chrome.exe"
WScript.sleep 400
WshShell.sendkeys "URL HERE"
WshShell.sendkeys "{ENTER}"

你也可以这样做来关闭chrome:

WshShell.sendkeys "%{F4}"

答案 3 :(得分:1)

  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()