A进程CreateProcess了B进程,A怎么知道B已经退出了?

解决方案 »

  1.   

    When the last thread in a process terminates, the following events occur: All objects opened by the process are implicitly closed. 
    The process’s termination status (which is returned by GetExitCodeProcess) changes from its initial value of STILL_ACTIVE to the termination status of the last thread to terminate. 
    The thread object of the main thread is set to the signaled state, satisfying any threads that were waiting on the object. 
    The process object is set to the signaled state, satisfying any threads that were waiting on the object. 
      

  2.   

    A创建B的时候,保留进程B的句柄,可以通过WaitSingleObject来等待B进程结束
      

  3.   

    事情是这样子的,我用的是setupfactory做的游戏安装包.
    我用WaitForSingleObject(pi.hProcess,INFINITE);等待的时候,马上就返回了,
    我猜测是这样的:这个安装程序启动了Setupfactory程序,然后自己就退出了,接下来由Setupfactory程序来负责安装,这样等待马上就结束了,而安装程序还在运行.
    我现在用定时去检测
      

  4.   

    WaitForSingleObject是等待有信号啊,程序一创建好当然马上就返回了!!
      

  5.   

    1、首先,在CreateProcess的STARTUPINFO参数里有这样几个hStdInput、hStdOutput、hStdError,用来为创建的进程指定输入输出,例如用CreateFile创建一个文件,接着把得到的文件句柄指定给hStdOutput,并且把dwFlags的值设为USESTDHANDLES,这样外部程序的输出就会输到这个文件里。注意:CreateFile的SECURITY_ATTRIBUTES.bInheritHandle参数要设为TRUE。
    2、在Create系列函数中通常都会有一个叫SECURITY_ATTRIBUTES的参数,比如:SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(SECURITY_ATTRIBUTES);sa.lpSecurityDescriptor = NULL;sa.bInheritHandle = TRUE;
    如果把bInheritHandle的值设为TRUE,意思就是它所创建出来的东西是可以被其他的子进程使用的,例如用CreatePipe创建的管道可以用在CreateProcess创建的进程中。3、用CreateProcess创建子进程时通过lpCurrentDirectory参数指定子进程运行的路径
      

  6.   

    其次:
    what is 线程
    LPSTARTUPINFOA lpStartupInfo;
    CreateProcess(
        PCSTR lpApplicationName,//可执行文件
        PSTR lpCommandLine,//传递给新进程的字符 (可以设置NULL)
        PSECURITY_ATTRIBUTES lpProcessAttributes,//进程安全属性(可以设置NULL)
        PSECURITY_ATTRIBUTES lpThreadAttributes,//线程安全属性(可以设置NULL,表示系统默认属性)
        BOOL bInheritHandles,//继承性(在这里实质False)
        DWORD dwCreationFlags,//规定如何创建线程(可设置NULL)
        PVOID lpEnvironment,//环境字符串的内存(继续为NULL)
        LPCSTR lpCurrentDirectory,//父进程实质子进程的当前驱动和目录(继续为NULL)
        &lpStartupInfo,//这个很重要的,不能为NULL
        LPPROCESS_INFORMATION lpProcessInformation//为空
        );
      

  7.   

    事情是这样子的,我用的是setupfactory做的游戏安装包.
    我用WaitForSingleObject(pi.hProcess,INFINITE);等待的时候,马上就返回了,
    我猜测是这样的:这个安装程序启动了Setupfactory程序,然后自己就退出了,接下来由Setupfactory程序来负责安装,这样等待马上就结束了,而安装程序还在运行.
    我现在用定时去检测