How to download an exe file from the internet

Jun 18, 2010 at 1:52pm
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
Jun 19, 2010 at 3:54am
if you are using Windows OS, click mouse right button and then save as...
save a *.exe file to the location you want to...
Jun 19, 2010 at 1:27pm
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
Jun 21, 2010 at 4:03am
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 Jun 21, 2010 at 4:04am
Jun 21, 2010 at 10:02am
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...
Jun 21, 2010 at 6:13pm
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;
}
Jun 21, 2010 at 10:43pm
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 Jun 21, 2010 at 10:43pm
Jun 21, 2010 at 10:49pm
It compiles under VC++. Obviously <urlmon.h> is a compiler specific header.
Jun 21, 2010 at 10:53pm
Is there an alternate to vc++ that can compile it or a way I can add it to dev c++,
Jun 22, 2010 at 7:31am
download the header file?
Jun 22, 2010 at 12:37pm
Just to be sure, you are compiling on windows? :P
Jun 22, 2010 at 2:13pm
The target is windows but I can compile on windows or Mac.
Jun 26, 2010 at 9:16am
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 Jun 26, 2010 at 9:17am
Jun 26, 2010 at 9:41pm
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.
Jun 26, 2010 at 10:10pm
You could always download and use visual studio express edition which is free.
Jun 27, 2010 at 1:15pm
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 Jun 27, 2010 at 1:18pm
Jun 27, 2010 at 6:59pm
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 Jun 27, 2010 at 7:01pm
Jun 27, 2010 at 8:52pm
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.
Jun 28, 2010 at 12:18am
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.