- // 将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();
- }
http://blog.csdn.net/visualeleven/article/details/6035381