Professional Documents
Culture Documents
– 4
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
PROCESS_INFORMATION pi;
if(!CreateProcess(L"c:\\WINDOWS\\system32\\calc.exe",NULL,NULL,FALSE,0,NULL,NULL,NULL,&si,&pi ))
//OR
//LPCWSTR target = _T("c:\\WINDOWS\\system32\\calc.exe");
//if(!CreateProcess(target,NULL,NULL, FALSE, NULL,NULL, NULL, NULL, &si, &pi) )
{
cout<<"CreateProcess failed \n"<<GetLastError() ;
}
else
{
cout << "Waiting on process for 10 seconds.." << endl;
WaitForSingleObject(pi.hProcess, 10 * 1000);
// to close app
if ( PostThreadMessage(pi.dwThreadId, WM_QUIT, 0, 0) )
cout << "Request to terminate process has been sent! \n";
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
getchar();
return 0;
}