SoFunction
Updated on 2025-03-10

Batch API code to implement file download page 1/2

Author: ZV(ZVROP)
Table of contents:
1.Writes written in the front
2. The cause of the story
3. Solution-Abdominal draft
4. Solve - Practical combat
5. Solve - Build
Six. Packaging
Seven. Section
8. Postscript
Nine, References


Start of the text:

1.Writes written in the front
This document is not about new technologies. I just mixed them together to realize the functions I need. If you have a good understanding of batch processing and PE formats, then my document will be treated as a browsing and review...^_^...
In addition, since I talk a lot of nonsense, this is the main reason why I don’t want to write articles for magazines. I can tell what I can say with a shaggy 3,000 words. It’s better to be so refreshing without restrictions (of course there is no reward... one_ one...). So to prevent you from falling asleep while reading articles, please bring your own small awl...
Finally, this document says that it is a batch process to download files. In fact, it contains a lot of knowledge. If you have time, you might as well take a look. ^_^, and you have started buying melons.

2. The cause of the story

The idea was first born when not long ago, a member of the UNIX SHELL section on the forum (advertisement http://) posted a post, which was written in a script for downloading pictures in batches (actually H pictures... one_ one...). Next, there are many posts..., which are derived from PHP, VBS, C, C#, JAVA, and even communicate to multiple threads, and interruptions are continued... To quote Brother Hua, "Speechless, for the sake of MM photos, everyone is very motivated!"... Sweat~~...

After posting a PHP and C code (I feel that I am very motivated ~ 1_1...), I think it is very simple (because using scripts such as C or PHP to implement file downloads is a very basic thing). I began to try to implement it with Microsoft's most original script - Batch (batch) (the title of this article is to commemorate this place, 1_1.), which seems a bit incredible, because batch processing has almost no implementation of network support (of course, I admire you if you say you can download files with TELNET... 1_1...), but there is no way. After all, there are so many things that can be used in WINDOWS, and there is no way to do it... Under the seduction of this challenge, I completed the function of downloading files with batch... Now let me play back my ideas step by step and uncover the secret of downloading files with batch...


3. Solution-Abdominal draft

If you use batch processing to download files, you will definitely think of Cscript scripts (or JAVA scripts). Of course, when too many batch scripts implement some functions that are impossible to implement themselves, they use ECHO to solve the problem. However, our purpose is to use batch processing to realize the download function. If you want to use VBS to help, it is better to write VBS directly. This idea will fail...

Next, I remember that there was a popular API in DLL for a while before using RUNDLL32 to load APIs in DLL, which seemed to be related to the purpose we needed, because there are too many APIs that can be used to download files. If RUNDLL can be called, it would be best. So I opened MSDN and found an API: URLDownloadToFile

URLDownloadToFile function prototype:

Code

HRESULT URLDownloadToFile(
LPUNKNOWN pCaller,
LPCTSTR szURL,
LPCTSTR szFileName,
DWORD dwReserved,
LPBINDSTATUSCALLBACK lpfnCB
);




Some information about the URLDownloadToFile function:


Quote

Header
Import library
Minimum availability Internet Explorer 3.0
Minimum operating systems Windows NT 4.0, Windows 95