Download an image from a website.
This is an example function to download an image from the internet with vbscript.
'*****************************************************************
'** Script: getimage.vbs
'** Version: 1.0
'** Created: 8-1-2009 17:08:48
'** Author: Adriaan Westra
'** E-mail:
'** Purpose / Comments:
'** Download an image from a web page.
'**
'**
'** Changelog :
'** 8-1-2009 17:08:41 : Initial version
'**
'*****************************************************************
Const adSaveCreateOverWrite = 2
Const adTypeBinary = 1
strSource = "http://www.westphil.nl/album/full/bloemen/DSC_4777.jpg "
strDest = "C:\temp\test.jpg"
'*****************************************************************
'** Download the image
strResult = GetImage(strSource, strDest)
If strResult = "OK" Then
wscript.quit(0)
Else
wscript.quit(1)
End If
Function GetImage(strPath, strDest)
Dim objXMLHTTP, nF, arr, objFSO, objFile
Dim objRec, objStream
'create XMLHTTP component
Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
'get the image specified by strPath
objXMLHTTP.Open "GET", strPath, False
objXMLHTTP.Send
'check if retrieval was successful
If objXMLHTTP.statusText = "OK" Then
'create binary stream to write image output
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
objStream.Write objXMLHTTP.ResponseBody
objStream.SavetoFile strDest, adSaveCreateOverwrite
objStream.Close
GetImage = "OK"
Else
GetImage = objXMLHTTP.statusText
End If
End Function