如何在VBS中打开网页

时间:2015-11-05 01:40:53

标签: vbscript

我的代码是

Set WshShell = CreateObject("WScript.shell")
for i = 0 to 50
WshShell.SendKeys(chr(175))
next
Process.Start("CMD", "/C  start chrome.exe http://www.example.com")

将音量设置为已满,然后将chrome打开到example.com。但是当我运行它时,我得到了这个错误:

Cannot use parentheses while calling a Sub

如何让它提高音量,然后转到网页?

4 个答案:

答案 0 :(得分:1)

尝试这样:

Option Explicit
Dim URL,WshShell,i
URL = "www.yahoo.com"
Set WshShell = CreateObject("WScript.shell")
For i = 0 to 50
    WshShell.SendKeys(chr(175))
Next
WshShell.run "CMD /C start chrome.exe " & URL & "",0,False

答案 1 :(得分:1)

wshshell.run "www.youtube.com"

答案 2 :(得分:0)

在调用带括号的sub时,VBScript需要CALL关键字。您可以像这样编写代码:

Set WshShell = CreateObject("WScript.shell")
For i = 0 To 50
    WshShell.SendKeys Chr(175)
Next
Process.Start "CMD", "/C  start chrome.exe http://www.example.com"

......或者像这样:

Set WshShell = CreateObject("WScript.shell")
For i = 0 To 50
    Call WshShell.SendKeys(Chr(175))
Next
Call Process.Start("CMD", "/C  start chrome.exe http://www.example.com")

注意:调用函数并使用其返回值时,您不会收到此错误,如下所示:

Dim strTest
strTest = SomeFunction()

...因为在赋值中使用函数时,VBScript总是需要括号。

答案 3 :(得分:-1)

这种方式对我有用。

set wshshell = wscript.CreateObject("wscript.shell")
wshshell.run "chrome.exe https://stackoverflow.com"

您可以将 chrome.exe 更改为任何浏览器或将网站更改为您想要的任何内容

相关问题