Thursday, September 27, 2007

VBScript to Retrieve a file from an URL and save it to the Hard Disk

'Script Start


URL = "http://sitename/filename.txt"
saveTo = "C:\filename.txt"

Set Obj1 = CreateObject("MSXML2.ServerObj1")
Obj1.open "GET", URL, false
Obj1.send()
Set Obj2 = CreateObject("ADODB.Stream")
Obj2.Open
Obj2.Type = 1 'adTypeBinary
Obj2.Write Obj1.ResponseBody 'Give the XML string to the ADO Stream
Obj2.Position = 0 'Set the stream position to the start
Set FSO = Createobject("Scripting.FileSystemObject")
if fso.Fileexists(saveTo) then Fso.DeleteFile hdLocation
set FSO = Nothing
Obj2.SaveToFile saveTo
Obj2.Close
Set Obj2 = Nothing
Set Obj1 = Nothing




'Script End

Got from the site www.vittorio.tk

How to execute a VBScript

No comments: