VBS going to a URL in the background

梦想与她 提交于 2019-12-20 03:50:15

问题


I would like to have my VB script go to a URL in the background. It can open a browser in the background and close it afterwards. The more "silent" the better. I had 2 implementations that work on my machine but doesn't work on another:

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

Here's another:

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

...where myURL is a string variable containing the URL.

I can't figure out why either of the above works on my laptop but not on the server. Any help would be appreciated.


回答1:


If you're looking for a silent approach I'd suggest to drop the Internet Explorer COM object entirely and go for an XMLHttpRequest object:

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

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

WScript.Echo req.ResponseText



回答2:


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


来源:https://stackoverflow.com/questions/14835669/vbs-going-to-a-url-in-the-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!