是关于软件更新的先启动主程序(称Main.exe)要更新文件就得启动Update.exe 退出Main.exe进程更新相关文件在Main.exe中用下列代码创建进程Update.exeif( !CreateProcess(NULL, // no module name (use command line). cmdLine.GetBuffer(), // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. FALSE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi ) // Pointer to PROCESS_INFORMATION structure. ) { return false; }
然后在Update.exe 中找出Main.exe杀掉 再更新文件DWORD aProcesses[1024]; DWORD cbNeeded=0; EnumProcesses(aProcesses,sizeof(aProcesses),&cbNeeded); //得到系统所有进程 DWORD cProcesses=cbNeeded/sizeof(DWORD); for(DWORD idx=0;idx<cProcesses;idx++) { HANDLE hProcess=::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, FALSE,aProcesses[idx]); //得到进程的HANDLE CString sName(""); if(NULL!=hProcess) { HMODULE hMod; DWORD cbNeeded; if(EnumProcessModules(hProcess,&hMod,sizeof(hMod),&cbNeeded)) //得到MODULE的句柄 { DWORD dw=GetModuleBaseName(hProcess,hMod,sName.GetBuffer(MAX_PATH), MAX_PATH); //得到MODULE名 sName.ReleaseBuffer(); } if(sName.CompareNoCase("room.exe")==0) { TerminateProcess(hProcess,0); } CloseHandle(hProcess); } ...... //更新文件
问题出来了 如果自己手动启动Update.exe 更新文件没问题(可以找出Main.exe并杀掉)但是照以上代码执行 更新文件不行(估计是没能杀掉Main.exe)是什么问题呢 是CreateProcess()里的参数设置不对还是其他的什么问题?
高手指点!