C++执行命令行并隐藏DOS窗口

10年前

  boolean execCMD(char* szCommandLine){

           STARTUPINFO StartInfo ={sizeof(StartInfo)}; // name structure

           StartInfo.dwFlags =STARTF_USESHOWWINDOW;

           StartInfo.wShowWindow = SW_HIDE;//隐藏DOC窗口

           PROCESS_INFORMATION ProcInfo; // name structure

           memset(&ProcInfo, 0, sizeof(ProcInfo));

           boolean flag = CreateProcess(NULL,szCommandLine, NULL, NULL, NULL, NULL, NULL, NULL, &StartInfo, &ProcInfo);

           if(flag){

                    

                            WaitForSingleObject(ProcInfo.hProcess,INFINITE);//此方法主要是等待进程处理

                     CloseHandle(ProcInfo.hThread);  

                     CloseHandle(ProcInfo.hProcess); 

 

           }

        

           return flag;

  }