VC windows 执行进程的方法 源码

来源:互联网 发布:cup tower软件下载 编辑:程序博客网 时间:2024/06/04 19:25
执行一个程序
void ShellExeA(LPCSTR lpFile, LPCSTR lpParameters){SHELLEXECUTEINFOA ShExecInfo;ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;ShExecInfo.hwnd = NULL;ShExecInfo.lpVerb = NULL;ShExecInfo.lpDirectory = NULL;ShExecInfo.nShow = SW_HIDE;ShExecInfo.hInstApp = NULL; ShExecInfo.lpFile = lpFile;ShExecInfo.lpParameters = lpParameters; ShellExecuteExA(&ShExecInfo);}


执行程序并等待程序结束

BOOL DealExecCmd(CString strCommandLine){USES_CONVERSION;STARTUPINFO StartInfo;memset(&StartInfo, '\0', sizeof(StartInfo));StartInfo.cb = sizeof(StartInfo);  //name structureStartInfo.dwFlags = STARTF_USESHOWWINDOW;StartInfo.wShowWindow = SW_HIDE;  //隐藏DOC窗口PROCESS_INFORMATION ProcInfo;     //name structurememset(&ProcInfo, 0, sizeof(ProcInfo));BOOL flag = ::CreateProcess(NULL, strCommandLine.GetBuffer(), NULL, NULL, NULL, NULL, NULL, NULL, &StartInfo, &ProcInfo);strCommandLine.ReleaseBuffer();if(flag){WaitForSingleObject(ProcInfo.hProcess,INFINITE);//此方法主要是等待进程处理,新的进程结束就会进行下一步DWORD dwExitCode = -1; GetExitCodeProcess(ProcInfo.hProcess, &dwExitCode);CloseHandle(ProcInfo.hThread);CloseHandle(ProcInfo.hProcess);}return flag;}


原创粉丝点击