This is wrong : If ShellExecute succeeds, and the first OpenProcess succeeds, you have a handle to the process which you never close. That means the process-object will never be released from memory, not even when the process has finished. So the second call to OpenProcess will succeed too, even if the process has finished in the meantime. You create 10 handles every second. If you let it run long enough you will run out of system resources.
What you need to do is:
1. obtain a handle to the process only once. Do it your way or, if you used CreateProcess like Ion suggested, you can use processInformation.hProcess immediately after CreateProcess succeeded.
2. call WaitForSingleObject, using the handle from step 1.
3. DO NOT FORGET: Close the process-handle (and thread-handle processInformation.hThread if you used CreateProcess).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.