We call CreateProcessAsUser() and, after having checked the result, we start tracking (WMI) the process that might create other processes.
In 1 case, the first process is so fast that it creates another process and terminates before we can start tracking it.
I even tried to not check the result and start immediately to track after the call to CreateProcessAsUser(), but it's not fast enough.
My idea is to start the process from a launcher.exe so we can track all the generated processes.
Is there any other alternative solution? We have the PID of the terminated process.
if we start child process and want way when it and all the children processes terminate we can use job object. general steps
create new job object via
CreateJobObjectWset
JobObjectAssociateCompletionPortInformationwithSetInformationJobObjectcreate new process in suspended state (use
CREATE_SUSPENDEDflag)add process to job via
AssignProcessToJobObjectresume new process with
ResumeThreadnow system will be send notifications to our completion port when new process will be started or exit. when no more process in job - will be
JOB_OBJECT_MSG_ACTIVE_PROCESS_ZEROmessage post to port - Indicates that the active process count has been decremented to 0of course we need create I/O completion port too by
CreateIoCompletionPortand one or more (if only for this task - single thread more than enough) threads which will be callGetQueuedCompletionStatuson port until end signal.we can for example use lpCompletionKey as pointer to object with virtual functions, and every object know how handle action event. demo code: