建立一處理程序,讓他執行一些工作,然後等候結果

Post date: 2012/9/10 上午 09:30:51

#include <windows.h>

int main(void)

{

_PROCESS_INFORMATION pi;

DWORD dwExitCode;

STARTUPINFO startupInfo = {0};

startupInfo.cb = sizeof(startupInfo);

BOOL fSuccess = ::CreateProcess(

L"C:\\Windows\\notepad.exe",

NULL,

NULL,

NULL,

FALSE,

NORMAL_PRIORITY_CLASS,

NULL,

NULL,

&startupInfo,

&pi

);

if(fSuccess)

{

CloseHandle(pi.hThread);

WaitForSingleObject(pi.hProcess,INFINITE);

GetExitCodeProcess(pi.hProcess,&dwExitCode);

CloseHandle(pi.hProcess);

}


return 0;

}