自己写好了一个exe,然后用WinExec去调用(主要是参数比较简单)。
WinExec("SetProxycn.exe",SW_SHOW);
在工程中我是这样做的:……//执行其他的任务
WinExec("SetProxycn.exe",SW_SHOW);
……//紧接着执行其他的任务
上面代码中由WinExec调用起来的SetProxycn.exe和主工程是并行运行的,现在我想串行运行,即当SetProxycn.exe运行完成后再运行下面的代码,该怎么整呢?ShellExecute和CreateProcess是否能够做到?

解决方案 »

  1.   


     STARTUPINFO si;
        PROCESS_INFORMATION pi;    ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );    
        // Start the child process. 
        if( !CreateProcess( _T("SetProxycn.exe"),   // No module name (use command line)
            NULL,        // 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
        ) 
        {
            printf( "CreateProcess failed (%d)\n", GetLastError() );
            return;
        }    // 等待进程结束.
        WaitForSingleObject( pi.hProcess, INFINITE ); // <=====================    // Close process and thread handles. 
        CloseHandle( pi.hProcess );
        CloseHandle( pi.hThread );