将EXE作为资源,然后在释放到磁盘上并运行该exe程序

// 将exe作为资源加入,然后再释放出来,并运行 try { HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(IDR_EXE1), _T("EXE")); if(NULL == hRes) return ; DWORD dwSize = SizeofResource(NULL, hRes); if(0 == dwSize) return ; HGLOBAL hGlobal = LoadResource(NULL, hRes); if(NULL == hGlobal) return ; LPVOID lp = LockResource(hGlobal); if(NULL == lp) return ; CFile file; TCHAR szApp[MAX_PATH] = {_T("F://11.exe")}; file.Open(szApp, CFile::modeCreate | CFile::modeWrite); file.WriteHuge(lp, dwSize); file.Close(); FreeResource (hGlobal); if(PathFileExists(szApp)) { STARTUPINFO si = {sizeof(si)}; PROCESS_INFORMATION pi = {0}; if(CreateProcess(NULL, szApp, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } } } catch (CException* e) { e->ReportError(); e->Delete(); }

你可能感兴趣的:(File,null,exe,Path,磁盘)