I need a script that can be run on freshly installed windows xp+ and download specified files from internet, like http://www.python.org/ftp/python/2.6.2/python-2.6.2.msi Is it any easy way to do it without hand-crafting HTTP/FTP requests or using third-party programs like wget? I can suggest that WScript.CreateObject("internetexplorer.application") will do the magic, but documentation on it is extremely huge and Google is silent, as always :).

link|improve this question

feedback

2 Answers

up vote 8 down vote accepted

Just found this one pasted below. You can run it with cscript and have it scheduled.

   'Set your settings
strFileURL = "http://www.domain.com/file.zip" strHDLocation = "D:\file.zip" ' Fetch the file Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") objXMLHTTP.open "GET", strFileURL, false objXMLHTTP.send() If objXMLHTTP.Status = 200 Then Set objADOStream = CreateObject("ADODB.Stream") objADOStream.Open objADOStream.Type = 1 'adTypeBinary objADOStream.Write objXMLHTTP.ResponseBody objADOStream.Position = 0 'Set the stream position to the start Set objFSO = Createobject("Scripting.FileSystemObject") If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation Set objFSO = Nothing objADOStream.SaveToFile strHDLocation objADOStream.Close Set objADOStream = Nothing End if Set objXMLHTTP = Nothing
link|improve this answer
+1 for streamline code. This looks much more efficient than using WScript.CreateObject("internetexplorer.application"). – KevinH Jun 22 '09 at 13:30
feedback

VBScript is annoying unco-operative when it comes to doing things like this. This sort of thing always requires COM servers that aren't formally part of the scripting engine.

Maxwell's suggestion of using MSXML2.XMLHTTP seems a cool way round this. I must admit I hadn't come across that trick before. There are also various commercial COM servers that will do file downoads.

This type of problem is one of the reasons I'm looking at shifting much of my VBScript to Powershell. Because Powershell can seamless use .Net objects, doing such things is a lot easier.

JR

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.