关于C++(MFC)执行外部EXE

关于C++(MFC)执行外部EXE

// 执行外部EXE
void RunAppToExit(CString sAppPath, CString sPara, int iWaitFlag, int iShowFlag);

// ------------------------------------------------------------------
// 执行外部EXE
// add by jzh 2009-07-05
// ------------------------------------------------------------------
void CommFunc::RunAppToExit(CString sAppPath, CString sPara, int iWaitFlag, int iShowFlag)
{
   SHELLEXECUTEINFO exeInfo;
   exeInfo.cbSize = sizeof(SHELLEXECUTEINFO);
   exeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;               //设置为SellExecuteEx函数结束后进程退出
   exeInfo.hwnd = NULL;
   exeInfo.lpVerb = "open";                               //执行动作为“打开执行”
   exeInfo.lpFile = (LPCTSTR) sAppPath;                   //执行程序文件全路径名称
   exeInfo.lpParameters = (LPCTSTR) sPara;                //执行参数
   exeInfo.lpDirectory = NULL;
   exeInfo.nShow = iShowFlag;                             //SW_SHOWNORMAL 1
   exeInfo.hInstApp = NULL;
   exeInfo.lpIDList = NULL;
   exeInfo.lpClass = NULL;
   exeInfo.hkeyClass = NULL;
   exeInfo.dwHotKey = NULL;
   exeInfo.hMonitor = NULL;
   exeInfo.hIcon = NULL;
   exeInfo.hProcess = NULL;
   
   ::ShellExecuteEx(&exeInfo);
   if (iWaitFlag = 0) 
   {
       if(exeInfo.hProcess)
       {
           ::WaitForSingleObject(exeInfo.hProcess,INFINITE);
           ::CloseHandle(exeInfo.hProcess);
       } 
   }
}

 

发表回复

您的电子邮箱地址不会被公开。