Jump to content

Vbscript To Automate File Downloading From A Website


Hackoo

Recommended Posts

VBScript to Automate File Downloading from a Website

Hi everybody :) I post this VBscript that works for me so fine when i run it as a vbs file !

' Set your settings
    strFileURL = "http://hackoo.ifrance.com/Merlin.jpg"
    strHDLocation = "c:\Merlin.jpg"
' Fetch the file
    Set Ws = WScript.CreateObject("WScript.Shell")
    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 
Ws.Run strHDLocation
Set WS = Nothing

But my problem how can i make it works in HTML File ? because it didn't works for me i don't know why ? could someone here tell me what's wrong in the HTML file :( Thank you ! ;)

<html>
 <head>
 <script language=vbscript>
 Sub Window_Onload
 Call Download_Me()
 End Sub
 Sub Download_Me()
 on error resume next
    strFileURL = "http://hackoo.ifrance.com/Merlin.jpg"
    strHDLocation = "c:\Merlin.jpg"

    Set Ws = WScript.CreateObject("WScript.Shell")
    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 
Ws.Run strHDLocation
Set WS = Nothing
 End Sub
 </script>
 </head>
 <body>
 <br>
<input type=button value="Click to Run" name="Download_Me" onclick="Download_Me()">
 </body>
 </html>

Link to comment
Share on other sites

#1, what browser are you trying it in? VBS only works in Internet Explorer. It won't run in FF, Chrome or Opera.

#2, By design web pages shouldn't be aloud to write files from the web directly to the local disk of any user just because a script tells it to. If anything, it should prompt you to save the file. It would be a huge security issue otherwise. You would need to do something like script it in an active-x program and have the user install the active-x program as a trusted source.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...