Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


kai4785

Command-line HTTP downloader for Win2k8r2

Recommended Posts

I know I'm being picky here, but I would prefer to not have to download/install 'wget' or 'curl' win32 binaries. I'm looking for a tool built into Windows Server 2008 R2. Is there such a thing? Even a 10 line vb script or something would be preferable.

Share this post


Link to post
Share on other sites

Sort of - bitsadmin.exe can do this, but it'll require you reading the documentation and monitoring the whole download via the exe. However, as of Vista, it ships with the OS if the BITS feature is installed (and I believe that is the default as well - my Server 2008 R2 machines all have BITS installed, and they're stock retail installs for repros that I rebuild every 15 days or so). Basically, you create a "job", add a file (or files) to a job, then resume and monitor it - when the download is/are complete, you have to "complete" the job.

Share this post


Link to post
Share on other sites

Wow, I'm kinda stuck between being surprised and not surprised. Bitsadmin is another example of a tool that's over kill for my needs. Maybe it is in my best interest to simply shove a wget executable into my WinPE image.

Thanks.

Share this post


Link to post
Share on other sites

bitsadmin is a tool that's not really designed to do what you want to do - it's more for large downloads over network connections it isn't supposed to saturate (hence why bits can be throttled back by pretty much any other network traffic). It can be used for such a thing, but wasn't designed to be used this way. Honestly, putting the wget binary onto a WinPE or Windows box if you plan on using it a lot is probably a lot better use if you want an easy way to do this and don't need the throttling bits can do (and it doesn't seem that you do).

Share this post


Link to post
Share on other sites

Errrm... is it just me or is PowerShell not really available in WinPE? (because of .NET)

Share this post


Link to post
Share on other sites

So it looks like I need a 64bit version of wget, since syswow64 is missing from WinPE, and I need 64bit WinPE to do 64bit Installs. I can't find any on google. Do I need to go compile my own?

Share this post


Link to post
Share on other sites

This VBscript can download HTTP files without any 3rd party tools. If you ask nicely, maybe someone would modify this to work with an external csv or text file. Then it could download all your files, and you'd be able to edit your list with notepad.

See robvanderwoude.com for greater detail

HTTPDownload "http://download.microsoft.com/download/4/A/A/4AA524C6-239D-47FF-860B-5B397199CBF8/windows-kb890830-v3.6.exe", "C:\"

Sub HTTPDownload( myURL, myPath )
' This Sub downloads the FILE specified in myURL to the path specified in myPath.
'
' myURL must always end with a file name
' myPath may be a directory or a file name; in either case the directory must exist
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
' Based on a script found on the Thai Visa forum
' http://www.thaivisa.com/forum/index.php?showtopic=21832

' Standard housekeeping
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Create a File System Object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFSO.FolderExists( myPath ) Then
strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
strFile = myPath
Else
WScript.Echo "ERROR: Target folder not found."
Exit Sub
End If

' Create or open the target file
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )

' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send

' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next

' Close the target file
objFile.Close( )
End Sub

Edited by MrJinje

Share this post


Link to post
Share on other sites

So it looks like I need a 64bit version of wget, since syswow64 is missing from WinPE, and I need 64bit WinPE to do 64bit Installs. I can't find any on google. Do I need to go compile my own?

Technically an x86 WinPE should be able to apply an x64 WIM file without issue, although if you're calling setup.exe to install Windows from media then yes, you'll need an x64 PE.

Share this post


Link to post
Share on other sites

I think this is exactly what I'll need. If I can get this integrated the way that I think I want it to, you've just made me a very happy camper.

Leave it to me to complain for weeks about how certain things can't be done, and then walk away for a month only minutes before a solution is presented. Curse my luck!

This VBscript can download HTTP files without any 3rd party tools. If you ask nicely, maybe someone would modify this to work with an external csv or text file. Then it could download all your files, and you'd be able to edit your list with notepad.

See robvanderwoude.com for greater detail

HTTPDownload "http://download.microsoft.com/download/4/A/A/4AA524C6-239D-47FF-860B-5B397199CBF8/windows-kb890830-v3.6.exe", "C:\"

Sub HTTPDownload( myURL, myPath )
' This Sub downloads the FILE specified in myURL to the path specified in myPath.
'
' myURL must always end with a file name
' myPath may be a directory or a file name; in either case the directory must exist
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
' Based on a script found on the Thai Visa forum
' http://www.thaivisa.com/forum/index.php?showtopic=21832

' Standard housekeeping
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Create a File System Object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFSO.FolderExists( myPath ) Then
strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
strFile = myPath
Else
WScript.Echo "ERROR: Target folder not found."
Exit Sub
End If

' Create or open the target file
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )

' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send

' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next

' Close the target file
objFile.Close( )
End Sub

Share this post


Link to post
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.   Restore formatting

  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...