STARTUPINFO si;
PROCESS_INFORMATION pi; memset(&si,0,sizeof(STARTUPINFO));
::CreateProcess(NULL,"notepad.exe",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);检查pi.dwProcessId是否有效,无效说明进程结束typedef struct _PROCESS_INFORMATION { // pi 
    HANDLE hProcess; 
    HANDLE hThread; 
    DWORD dwProcessId; 
    DWORD dwThreadId; 
} PROCESS_INFORMATION; 
 
Members
hProcess 
Returns a handle to the newly created process. The handle is used to specify the process in all functions that perform operations on the process object. 
hThread 
Returns a handle to the primary thread of the newly created process. The handle is used to specify the thread in all functions that perform operations on the thread object. 
dwProcessId 
Returns a global process identifier that can be used to identify a process. The value is valid from the time the process is created until the time the process is terminated. 
dwThreadId 
Returns a global thread identifiers that can be used to identify a thread. The value is valid from the time the thread is created until the time the thread is terminated. 

解决方案 »

  1.   

    int RunExe(const char * ProcessName,char * CommandLine)
    {
    STARTUPINFO si;
        PROCESS_INFORMATION pi;    ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );    // Start the child process. 
        if( !CreateProcess( ProcessName, // No module name (use command line). 
            CommandLine,   // 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.
        ) 
        {
            return 0;
        }    // Wait until child process exits.
        // 这里就可以等待它结束..如果自己不想程序死在这,那就起个线程就行了
        WaitForSingleObject( pi.hProcess, INFINITE );    // Close process and thread handles. 
        CloseHandle( pi.hProcess );
        CloseHandle( pi.hThread );
    return 1;}