VBS转到后台的URL

时间:2013-02-12 15:14:02

标签: url browser vbscript

我想让我的VB脚本转到后台的URL。它可以在后台打开浏览器并在之后关闭它。越“沉默”越好。我有2个实现可以在我的机器上工作,但不适用于另一个:

Set WshShell = WScript.CreateObject("WScript.Shell") 
Return = WshShell.Run("iexplore.exe " &  myURL, 1) 

这是另一个:

Set objExplorer = WScript.CreateObject _
("InternetExplorer.Application", "IE_")
objExplorer.Navigate myURL
'Determines if the window is visible or not
objExplorer.Visible = 0
'Suspend the script for 1 minute
WScript.Sleep 6000
'Close the IE (instantiated) window
objExplorer.quit

...其中myURL是包含URL的字符串变量。

我无法弄清楚为什么上述任何一种都可以在我的笔记本电脑上运行而不能在服务器上运行。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:5)

如果您正在寻找静默方法,我建议完全删除Internet Explorer COM对象并转到XMLHttpRequest对象:

myURL = "http://www.google.com/"

Set req = CreateObject("MSXML2.XMLHTTP.6.0")
req.Open "GET", myURL, False
req.Send

WScript.Echo req.ResponseText

答案 1 :(得分:-1)

Set WshShell = WScript.CreateObject("WScript.Shell") 
Return = WshShell.Run("iexplore.exe " &  myURL, 1) 
WScript.Sleep 10000
WshShell.SendKeys "{F6}"
WScript.Sleep 500
WshShell.SendKeys "y"
WScript.Sleep 500
WshShell.SendKeys "o"
WScript.Sleep 500
WshShell.SendKeys "u"
WScript.Sleep 500
WshShell.SendKeys "t"
WScript.Sleep 500
WshShell.SendKeys "u"
WScript.Sleep 500
WshShell.SendKeys "b"
WScript.Sleep 500
WshShell.SendKeys "e"
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500