How to download an exe file from the internet

Hello,

I am trying to find a way to download an .exe file from the internet. I already know how to install it ( I think... ) But I just cant get past the download. I also want it to go right to the C drive and not into a temp folder.

Thanks in advance,
Adam
if you are using Windows OS, click mouse right button and then save as...
save a *.exe file to the location you want to...
I thought this might happen... I guess I wasn't specific enough. I mean in the c++ code how to lets say, download file abcd.exe from google.com like this
1
2
3
4
5
6
7
8
9
10
11
#include<iostream>

using namespace std;

int main ()
{
     dload(www.google.com/files/abcd.exe, C:\downloads); //This is where I would download the file 
     system("C:\downloads\abcd.exe"); //This is where I would run the file
     system("PAUSE");
     return(0)
}


I know there are probably errors in this but this is just an example and I KNOW dload is not a command but I just put it there to hold the place if you know what I mean

Thanks,
Adam
You can use Wget... Either install it and use it in a system(), or take a look at the source code and figure out how it retrives files... (I don't know if it's in C/C++ though)
Wget and it's source code are available here:
http://gnuwin32.sourceforge.net/packages/wget.htm
Last edited on
On Linux you would use the socket library. On windows, you would use the winsock library or for maximum c00lness you can use the UNIX style socket library and compile with Cygwin when you want a windows executable.

Downloading a file with the socket library is really quite simple.

http://www.beej.us/guide/bgnet

In Python it's even simpler:
1
2
3
4
5
6
import urllib2

def download(url, filename):
        urlfile = urllib2.urlopen(url)
        localfile = open(filename, "w")
        localfile.write(urlfile.read())

but everything is simpler in Python...
I found someone with your same problem: http://www.codeguru.com/forum/showthread.php?threadid=463496

Solution:
1
2
3
4
5
6
7
8
#include <tchar.h>
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
int main()
{
	HRESULT hr = URLDownloadToFile ( NULL, _T("your web page"), _T("c:/web_page.html"), 0, NULL );
	return 0;
}
Programmer47,

The code that you gave will not compile in dev C++. It gives the following errors:

1
2
3
4
5
6
7
8
9
#include <tchar.h>
#include <urlmon.h> //"urlmon.h: No such file or directory found"
#pragma comment(lib, "urlmon.lib")
int main()
{
	HRESULT hr = URLDownloadToFile ( NULL, _T("your web page"), _T("c:/web_page.html"), 0, NULL );
 //"HRESULT undeclared (first use this function)" and "expected `;' before "hr" 
	return 0;
}
Last edited on
It compiles under VC++. Obviously <urlmon.h> is a compiler specific header.
Is there an alternate to vc++ that can compile it or a way I can add it to dev c++,
download the header file?
Just to be sure, you are compiling on windows? :P
The target is windows but I can compile on windows or Mac.
Am I right to think that you can just get a copy of urlmon.h from VC++, and place it into your Dev C++ include dir?

Then you would just #include <urlmon.h>
Last edited on
Unlikely. You probably need a library (say, "liburlmon.a" or "urlmon.lib") as well, and given that it's most likely distributed in the precompiled format, it won't be compatible with MinGW.
You could always download and use visual studio express edition which is free.
I am in the process of downloading VC++ Express and I will post my results, but where (If I need it) can I find the urlmon library?

Thanks,
Adam

*Edit*
P.S. Chris name you were right. I copied a urlmon.h (not from VC++) into dev c++'s include directory and it did not compile with out about a dozen more header files that I didnt have.
Last edited on
OK It compiles correctly when i use it once but when I try to use it a second time I get errors. here is the code...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "stdafx.h"
#include <tchar.h>
#include <urlmon.h>
#include <iostream>
using namespace std;
#pragma comment(lib, "urlmon.lib")
int main()
{
	cout << "downloading Piriform CCleaner...";
	HRESULT hr = URLDownloadToFile ( NULL, _T("http://download.piriform.com/ccsetup233.exe"), _T("c:/cleaner/ccleaner/install/ccsetup233.exe"), 0, NULL );
	cout << "Done!" << endl;
	cout << "downloading Piriform Defragler...";
	HRESULT hr = URLDownloadToFile ( NULL, _T("http://download.piriform.com/dfsetup120.exe"), _T("c:/cleaner/defragler/install/dfsetup120.exe"), 0, NULL );
	cout << "Done!" << endl;
	system("PAUSE");
}

error is: 'hr' : redefinition; multiple initialization
Last edited on
closed account (D80DSL3A)
That's because you are declaring the variable hr to exist twice. Omit HRESULT from line 13. You are just reusing the variable hr declared on line 10.
OK that compiles correctly.

I think that's it.

when I'm done I will post my code here and a .exe file if you guys want to try it or compile it yourselves.

Thanks so much for your help,
-Adam
Topic archived. No new replies allowed.