5 ' Redistribution and use is allowed according to the terms of the BSD license. |
5 ' Redistribution and use is allowed according to the terms of the BSD license. |
6 ' |
6 ' |
7 ' References |
7 ' References |
8 ' http://superuser.com/questions/59465/is-it-possible-to-download-using-the-windows-command-line |
8 ' http://superuser.com/questions/59465/is-it-possible-to-download-using-the-windows-command-line |
9 ' http://stackoverflow.com/questions/1021557/how-to-unzip-a-file-using-the-command-line |
9 ' http://stackoverflow.com/questions/1021557/how-to-unzip-a-file-using-the-command-line |
|
10 ' http://stackoverflow.com/questions/424331/get-the-current-temporary-directory-path-in-vbscript |
10 |
11 |
11 Set ArgObj = WScript.Arguments |
12 Set ArgObj = WScript.Arguments |
12 |
13 |
13 If (Wscript.Arguments.Count = 1) Then |
14 If (Wscript.Arguments.Count = 1) Then |
14 strFileURL = ArgObj(0) |
15 strFileURL = ArgObj(0) |
21 WScript.Echo ("Usage: csript.exe w32DownloadUnzip.vbs url output") |
22 WScript.Echo ("Usage: csript.exe w32DownloadUnzip.vbs url output") |
22 WScript.Quit |
23 WScript.Quit |
23 End if |
24 End if |
24 End if |
25 End if |
25 |
26 |
26 strHDLocation = "C:\Windows\Temp\temp.zip" |
27 ' Temporary directory |
|
28 strHDLocation = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2) + "\hwlibtemp.zip" |
27 |
29 |
28 ' Fetch the file |
30 ' Fetch the file |
29 WScript.Echo ( "Trying to download from " & strFileURL) |
31 WScript.Echo ( "Trying to download from " & strFileURL) |
30 Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") |
32 Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") |
31 objXMLHTTP.open "GET", strFileURL, false |
33 objXMLHTTP.open "GET", strFileURL, false |
35 Set objADOStream = CreateObject("ADODB.Stream") |
37 Set objADOStream = CreateObject("ADODB.Stream") |
36 objADOStream.Open |
38 objADOStream.Open |
37 objADOStream.Type = 1 'adTypeBinary |
39 objADOStream.Type = 1 'adTypeBinary |
38 |
40 |
39 objADOStream.Write objXMLHTTP.ResponseBody |
41 objADOStream.Write objXMLHTTP.ResponseBody |
40 objADOStream.Position = 0 'Set the stream position to the start |
42 objADOStream.Position = 0 'Set the stream position to the start |
41 |
43 |
42 Set objFSO = Createobject("Scripting.FileSystemObject") |
44 Set objFSO = Createobject("Scripting.FileSystemObject") |
43 If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation |
45 If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation |
44 Set objFSO = Nothing |
46 Set objFSO = Nothing |
45 |
47 |
46 objADOStream.SaveToFile strHDLocation |
48 objADOStream.SaveToFile strHDLocation |
47 objADOStream.Close |
49 objADOStream.Close |
48 Set objADOStream = Nothing |
50 Set objADOStream = Nothing |
|
51 Set objXMLHTTP = Nothing |
49 Else |
52 Else |
50 WScript.Echo ("Error downloading file (error code: " & objXMLHTTP.Status & ")") |
53 WScript.Echo ("Error downloading file (error code: " & objXMLHTTP.Status & ")") |
51 Set objXMLHTTP = Nothing |
54 Set objXMLHTTP = Nothing |
52 WScript.Quit |
55 WScript.Quit |
53 End if |
56 End if |
54 Set objXMLHTTP = Nothing |
|
55 |
57 |
56 WScript.Echo ( "Extracting file to " & strOutputPath) |
58 WScript.Echo ( "Extracting file to " & strOutputPath) |
57 Set objShell = CreateObject( "Shell.Application" ) |
59 Set objShell = CreateObject( "Shell.Application" ) |
58 Set objSource = objShell.NameSpace(strHDLocation).Items() |
60 Set objSource = objShell.NameSpace(strHDLocation).Items() |
59 Set objTarget = objShell.NameSpace(strOutputPath) |
61 Set objTarget = objShell.NameSpace(strOutputPath) |