Hi all, I just wanted to share a _vbscript_ that I have found that seems to be better than the default one provided with the chef client. I have been struggling for a while now with the script that fails on some machines and not others. I admit the windows setup is not ideal where I am but it is likely that I am not the one. The point is that this script tries a few different approaches before giving up. I have not fully appreciated how it does it… I was mostly happy that it works! I found the script here: http://www.ericphelps.com/scripting/samples/BinaryDownload/ Below is the drop-in replacement script that I slightly adapted to work with the chef code in
strUrl = WScript.Arguments.Named("url") strFile = WScript.Arguments.Named("path") Const adTypeBinary = 1 Const adSaveCreateOverWrite = 2 Const ForWriting = 2 Dim web, varByteArray, strData, strBuffer, lngCounter, ado On Error Resume Next 'Download the file with any available object Err.Clear Set web = Nothing Set web = CreateObject("WinHttp.WinHttpRequest.5.1") If web Is Nothing Then Set web = CreateObject("WinHttp.WinHttpRequest") If web Is Nothing Then Set web = CreateObject("MSXML2.ServerXMLHTTP") If web Is Nothing Then Set web = CreateObject("Microsoft.XMLHTTP") web.Open "GET", strURL, False web.Send If Err.Number <> 0 Then SaveWebBinary = False Set web = Nothing Wscript.Quit End If If web.Status <> "200" Then SaveWebBinary = False Set web = Nothing Wscript.Quit End If varByteArray = web.ResponseBody Set web = Nothing 'Now save the file with any available method On Error Resume Next Set ado = Nothing Set ado = CreateObject("ADODB.Stream") If ado Is Nothing Then Set fs = CreateObject("Scripting.FileSystemObject") Set ts = fs.OpenTextFile(strFile, ForWriting, True) strData = "" strBuffer = "" For lngCounter = 0 to UBound(varByteArray) ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1))) Next ts.Close Else ado.Type = adTypeBinary ado.Open ado.Write varByteArray ado.SaveToFile strFile, adSaveCreateOverWrite ado.Close End If SaveWebBinary = True |
Archive powered by MHonArc 2.6.16.