Reputation:
How can the exit code of the main thread be retrieved, after having run ShellExecuteEx() in asychronous mode?
The process exit code can simply be retrieved as follows:
SHELLEXECUTEINFO execInfo;
execInfo.cbSize = sizeof(SHELLEXECUTEINFO);
execInfo.fMask = SEE_MASK_NOASYNC;
ShellExecuteEx(&execInfo);
/* Get process exit code. */
DWORD processExitCode;
GetExitCodeProcess(execInfo.hProcess, &processExitCode);
But how can the exit code of the main thread be retrieved? What should be passed to GetExitCodeThread()?
Upvotes: 0
Views: 2792
Reputation: 12951
In order to get the exit code of the primary process thread - one has to obtain its HANDLE
. Unfortunately ShellExecuteEx
doesn't return you this (it returns only the HANDLE
of the newly created process).
One could also enumerate all the threads in a particular process and open their handles (OpenThread
). Thus, you could create a process in a "suspended" state, get the handle of its only thread (which didn't start execution yet), and then go on.
Alas, ShellExecuteEx
neither allows you to create a new process in a suspended state.
So that I don't see a clean way to achieve what you want. I'd suggest the following:
CreateProcess
. It has the needed functionality.Upvotes: 0
Reputation: 2740
The exit code of the main thread is equal to the exit code of the process IMHO.
Upvotes: 1