Remy Lebeau replied to Jeff McKay
20-Nov-09 02:36 PM

You do not need to use OpenProcess() for that. CreateProcess() returns =
both the Process ID and Process Handle of the launched process. Use =
those values as-is. You can pass the Process Handle to =
GetExitCodeProcess() or any of the WaitFor...() functions to detect if =
the process is running. Just be sure to close the Process Handle when =
you are done using it.
Not necessarily. If you do not close the handle that CreateProcess() =
returns, the child process remains alive in memory, even if it is not =
running anymore. That way, you can call GetExitCodeProcess() and other =
process-related functions on the child process. Worse, you are =
re-opening the Process ID, which has no clue if the original child =
process is still attached to that ID anymore. OpenProcess() opens =
whatever current process is using that ID. The OS can reuses a =
process's ID after the process is fully terminated. All the more reason =
to use the Process Handle that CreateProcess() gives you instead.
The killed Process ID was likely reused by the OS before you had a =
chance to call OpenProcess().
--=20
Remy Lebeau (TeamB)