6

我正在尝试编写一些 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

4 回答 4

15

As String,因为 VBScript 不是强类型,所以set在创建 COM 对象的实例时需要一个并且在方法调用周围没有括号;

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)
于 2012-11-15T16:26:31.543 回答
2

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

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

也只是一个 fyi 你可以这样做来关闭 chrome:

WshShell.sendkeys "%{F4}"
于 2016-01-27T15:16:06.560 回答
1

你能在“objShell.ShellExecute”中插入“Call”前缀吗

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

IE:

'objShell.ShellExecute "iexplore.exe", iURL, "", "", 1
于 2014-08-23T06:53:41.170 回答
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()
于 2020-04-09T15:30:47.427 回答