The GetExitCodeProcess function retrieves the termination status of the specified process.
BOOL GetExitCodeProcess(
HANDLE hProcess, // handle to the process
LPDWORD lpExitCode // termination status
);
下面也是一个办法:
C/C++ Code Example: Retrieving Task Exit Code
This example retrieves the last exit code returned by a known task. (A returned value of "0" indicates the task was never run.) The example assumes that the task, Test Task, already exists on the local computer.
int main(int argc, char **argv)
{
HRESULT hr = ERROR_SUCCESS;
///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}
///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"TestTask";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);
///////////////////////////////////////////////////////////////////
// Call ITask::GetExitCode. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
DWORD pdwExitCode;