HELP! how do i auto-download?

RoddyVR

Veteran Board NESer
Joined
Mar 29, 2002
Messages
4,210
Location
Russian in US
i need to make a file that i can give to someone that when run (or if they press some button in it) will download 2 files from a webpage into a specific directiory on their PC.

i cant spend another hour on the phone with this person to explain how to get these 2 files to work together, and would prefer to automate the process for her.

i tried to get a DOS batch file to 'copy' the files, but it doesnt understand web adreeses.
i tried making an html file to send her with links to the files, but i cant figure out how to get the links to know where to put the files. (they are Microsoft Access files)

if someone could help, i would GREATLY appreciate.
there HAS to be a way to do it.
 
Only way I know of is to learn a programming language and make a program to do that, or get someone else to make it for you.
 
I don't have a VB compiler at work, so I have written it in VBA rather than VB. You can just drop it into a module in Excel / Word and run it from there.

What you are asking is fairly straight-forward (providing the computer it will be run from has win 9x as the OS).

The complexity of the code required increases if the program has to connect to the internet, so to simplify things, just connect first :) (the code checks whether a connection is present).

You will have to modify the code to reflect the actual files you want to download, and where you want them to be downloaded to. Copy/paste a second section for the second file, or loop it. If you're not sure how to do this / put the code into Excel, let me know (sorry, I don't know how familiar you are with using Excel/Word VBA - I could even post it as a spreadsheet, if you like :) )



Code:
[color=blue]Private Declare Function[/color] URLDownloadToFile [color=blue]Lib[/color] "urlmon" _
[color=blue]Alias[/color] "URLDownloadToFileA" _
  ([color=blue]ByVal[/color] pCaller [color=blue]As Long, ByVal[/color] szURL [color=blue]As String, _
   ByVal [/color]szFileName [color=blue]As String, ByVal [/color]dwReserved [color=blue]As Long, _
   ByVal [/color]lpfnCB [color=blue]As Long[/color]) [color=blue]As Long

Private Declare Function[/color] InternetGetConnectedState [color=blue]Lib[/color]  "wininet" _
  ([color=blue]ByRef[/color]  dwflags [color=blue]As Long, ByVal[/color]  dwReserved [color=blue]As Long[/color] ) [color=blue]As Long


Sub[/color] DownloadFile()
[color=green]'Check for internet connection.[/color]
[color=blue]Dim[/color] boolConnected [color=blue]As Boolean[/color]

boolConnected = InternetConnectedState(0&,0&)
[color=blue]If[/color] boolConnected = [color=blue]False Then[/color]
    MsgBox "Internet Connection not found.  Please connect " _ 
    & "to the internet and try again."
    [color=blue]Exit Sub
End If[/color]




[color=blue]Dim[/color] strSourceURL [color=blue]As String
Dim[/color] strTargetFileName [color=blue]As String[/color]

[color=green]'Change the following line to the URL you want to download from.[/color]
strSourceURL = "http://www.civfanatics.net/uploads/yoda.jpg"

[color=green]'Change the following to the target directory / file name you want.[/color]
strTargetFileName = "C:\apps\yoda.jpg"

MsgBox "Press OK to download file."

[color=blue]Dim[/color] lngAPIRetVal [color=blue]As Long[/color]

lngAPIRetVal = URLDownloadToFile(0&, strSourceURL, strTargetFileName, 0&, 0&)
                                 
[color=blue]If[/color] lngAPIRetVal = 0 [color=blue]Then[/color]
    MsgBox "Successfully downloaded " & strSourceURL & " to " _
    & vbCrLf & strTargetFileName
[color=blue]else[/color]
    MsgBox "Download failed!  API Returned " & lngAPIRetVal
[color=blue]End If

End Sub[/color]



Edit: This won't have any fancy progress indicators to let you know how the downlaod is progressing, so if it is a big file, it may look like the program has frozen for the duration of the download.
 
wow, cool.
thanks ainwood

i can handle the small editing for file names and so forth no prob. thanks, thats a big help.
 
A self-unzipper could work too...just tell them to select "run from current location" and then the unzipper would put the files in the correct location.
 
simple, but effective.
i gotta remember this for next time i send her these files(or their future counterparts)

Thanks guys, you've been a great help. saved me atleast an hour of time AND taught me something new. :D
 
Back
Top Bottom