I am not able to kill a child process using TerminateProcess

Posted by user1681210 on Stack Overflow See other posts from Stack Overflow or by user1681210
Published on 2012-09-18T21:31:42Z Indexed on 2012/09/18 21:38 UTC
Read the original article Hit count: 224

Filed under:
|

I have a problem to kill a child process using TerminateProcess. I call to this function and the process still there (in the Task Manager) This piece of code is called many times launching the same program.exe many times and these process are there in the task manager which i think is not good.

sorry, I am quiet new in c++

I will really appreciate any help. thanks a lot!!

the code is the following:

  STARTUPINFO childProcStartupInfo;
   memset( &childProcStartupInfo, 0, sizeof(childProcStartupInfo));
   childProcStartupInfo.cb = sizeof(childProcStartupInfo);
   childProcStartupInfo.hStdInput = hFromParent;   // stdin
   childProcStartupInfo.hStdOutput = hToParent;    //  stdout
   childProcStartupInfo.hStdError = hToParentDup;  // stderr
   childProcStartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
   childProcStartupInfo.wShowWindow = SW_HIDE;


   PROCESS_INFORMATION childProcInfo;  /* for CreateProcess call */



    bOk = CreateProcess(
       NULL,           // filename
       pCmdLine,   // full command line for child
       NULL,           // process security descriptor */
       NULL,           // thread security descriptor */
       TRUE,           // inherit handles? Also use if STARTF_USESTDHANDLES */
       0,              // creation flags */
       NULL,           // inherited environment address */
       NULL,           // startup dir; NULL = start in current */
       &childProcStartupInfo,          // pointer to startup info (input) */
       &childProcInfo);            // pointer to process info (output) */

    CloseHandle( hFromParent );
    CloseHandle( hToParent );
    CloseHandle( hToParentDup );

    CloseHandle( childProcInfo.hThread);
    CloseHandle( childProcInfo.hProcess);

    TerminateProcess( childProcInfo.hProcess ,0);  //this is not working, the process 

thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about createprocess