i using following code execute 'taskkill' command using createprocess() api.
startupinfo si; process_information pi; zeromemory( &si, sizeof(si) ); si.cb = sizeof(si); zeromemory( &pi, sizeof(pi) ); tchar cmd[] = text("taskkill /f /t /im <exe name>"); if (createprocess(null, cmd, null, null, false, 0, null, null, &si, & pi)) { // wait child process exit dword waitforstatus = waitforsingleobject(pi.hprocess, 10000); // close process , thread handles closehandle(pi.hprocess); closehandle(pi.hthread); /* code throw exception based on return value waitforstatus */ } else { /* code throw exception if createprocess() failed */ }
what observed if process not running, task kill fails, crateprocess() not indicate error. how error createprocess?
is there possibilty process not killed taskkill /f switch?
createprocess
responsible spawning/creating sub-process (in case taskkill.exe
) successful, therefore returns true
. it's code's responsibility monitor sub-process , when ends exit code. calling getexitcodeprocess before closing handle:
getexitcodeprocess(pi.hprocess, &ec);
don't forget declare ec
first (as dword
). reverse order of handle closing (it's not mandatory, logically thread ends before process).
Comments
Post a Comment