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.
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
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
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
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
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.
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 <urlmon.h> //"urlmon.h: No such file or directory found"
#pragma comment(lib, "urlmon.lib")
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"