author | dag10 |
Mon, 14 Jan 2013 11:19:59 +0100 | |
changeset 8377 | 869f80966a77 |
parent 7813 | 7ac83d79b897 |
child 9069 | 24a2da6e5a22 |
permissions | -rw-r--r-- |
7810 | 1 |
' w32DownloadUnzip.vbs |
2 |
' Download a zipfile and uncompress it with no external tools in Windows |
|
3 |
' |
|
4 |
' Copyright (c) 2012, Vittorio Giovara, <vittorio.giovara@gmail.com> |
|
5 |
' Redistribution and use is allowed according to the terms of the BSD license. |
|
6 |
' |
|
7 |
' References |
|
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 |
|
10 |
||
11 |
Set ArgObj = WScript.Arguments |
|
12 |
||
13 |
If (Wscript.Arguments.Count = 1) Then |
|
14 |
strFileURL = ArgObj(0) |
|
15 |
strOutputPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") |
|
16 |
Else |
|
17 |
If (Wscript.Arguments.Count = 2) Then |
|
18 |
strFileURL = ArgObj(0) |
|
19 |
strOutputPath = ArgObj(1) |
|
20 |
Else |
|
21 |
WScript.Echo ("Usage: csript.exe w32DownloadUnzip.vbs url output") |
|
22 |
WScript.Quit |
|
23 |
End if |
|
24 |
End if |
|
25 |
||
26 |
strHDLocation = "C:\Windows\Temp\temp.zip" |
|
27 |
||
28 |
' Fetch the file |
|
7813
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
7810
diff
changeset
|
29 |
WScript.Echo ( "Trying to download from " & strFileURL) |
7810 | 30 |
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") |
31 |
objXMLHTTP.open "GET", strFileURL, false |
|
32 |
objXMLHTTP.send() |
|
33 |
||
34 |
If objXMLHTTP.Status = 200 Then |
|
35 |
Set objADOStream = CreateObject("ADODB.Stream") |
|
36 |
objADOStream.Open |
|
37 |
objADOStream.Type = 1 'adTypeBinary |
|
38 |
||
39 |
objADOStream.Write objXMLHTTP.ResponseBody |
|
40 |
objADOStream.Position = 0 'Set the stream position to the start |
|
41 |
||
42 |
Set objFSO = Createobject("Scripting.FileSystemObject") |
|
43 |
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation |
|
44 |
Set objFSO = Nothing |
|
45 |
||
46 |
objADOStream.SaveToFile strHDLocation |
|
47 |
objADOStream.Close |
|
48 |
Set objADOStream = Nothing |
|
49 |
Else |
|
50 |
WScript.Echo ("Error downloading file (error code: " & objXMLHTTP.Status & ")") |
|
51 |
Set objXMLHTTP = Nothing |
|
52 |
WScript.Quit |
|
53 |
End if |
|
54 |
Set objXMLHTTP = Nothing |
|
55 |
||
56 |
WScript.Echo ( "Extracting file to " & strOutputPath) |
|
57 |
Set objShell = CreateObject( "Shell.Application" ) |
|
58 |
Set objSource = objShell.NameSpace(strHDLocation).Items() |
|
59 |
Set objTarget = objShell.NameSpace(strOutputPath) |
|
60 |
intOptions = 16 'no user prompt |
|
61 |
objTarget.CopyHere objSource, intOptions |
|
62 |
||
7813
7ac83d79b897
support video recording on windows with automation and headers
koda
parents:
7810
diff
changeset
|
63 |
WScript.Echo ( "Success!" ) |
7810 | 64 |
Set objShell = Nothing |