2017年11月26日 星期日

[ Windows | MFC ] run DOS command in MFC

void Utility::runDosCmdAndWait(CString command, int maxWaitMS, CString path, int isShow)
{
     CString final_cmd = _T(" /C ") + command;

     SHELLEXECUTEINFO ShExecInfo = { 0 };
     ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
     ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
     ShExecInfo.hwnd = NULL;
     ShExecInfo.lpVerb = NULL;
     ShExecInfo.lpFile = _T("cmd");
     ShExecInfo.lpParameters = final_cmd;
     ShExecInfo.lpDirectory = path;
     ShExecInfo.nShow = isShow;
     ShExecInfo.hInstApp = NULL;
     ShellExecuteEx(&ShExecInfo);
     WaitForSingleObject(ShExecInfo.hProcess, maxWaitMS);
}


沒有留言: