Kill a process!!
-
Hi, This is my problem: I am using VC++ 6.0, and my program has to execute a shell application, this task is accomplished with the "ShellExecute", but my problem starts here. For example, if the command is indefinite (ping 10.0.0.1 -t), How can I kill this process with a VC++ sentence????? without execute the manual CTRL+C sorry for my english, thanks in advance
-
Hi, This is my problem: I am using VC++ 6.0, and my program has to execute a shell application, this task is accomplished with the "ShellExecute", but my problem starts here. For example, if the command is indefinite (ping 10.0.0.1 -t), How can I kill this process with a VC++ sentence????? without execute the manual CTRL+C sorry for my english, thanks in advance
Instead use ShellExecuteEx and get Process handle, followed with TerminateProcess.... Brian
-
Hi, This is my problem: I am using VC++ 6.0, and my program has to execute a shell application, this task is accomplished with the "ShellExecute", but my problem starts here. For example, if the command is indefinite (ping 10.0.0.1 -t), How can I kill this process with a VC++ sentence????? without execute the manual CTRL+C sorry for my english, thanks in advance
Try to avoid TerminateProcess() if possible. See MSDN description of TerminateProcess for the reasoning. Solutions depend on whether the child process has a top level window or are running in a console. I'll assume the child process you describe will be running in a console. One way is to... 1. Spawn child process with ShellExecuteEx() or CreateaProcess() 2. WaitForSingleObject(Handle_To_ChildProcessID,YourTimeOutValue)...consider putting this in worker thread 3. If times out, then kill child process ***NOTE: I have read about others getting CreateRemoteThread to work as described below but I personally have not confirmed this. CreateRemoteThread is available in NT/2K/XP. X| *** - CreateRemoteThread() using the ProcessID handle you got from CreateProcess and passing the address of ExitProcess() as the lpStartupAddress. ExitProcess() appears to be mapped to the same address in each processes address space. You can obtain this address by using the address from your process. - When the remote thread starts (and calls ExitProcess) within the child process, the child process can now "cleanly" terminate. If the child process has a top level window, then just PostMessage(HandleToChildsWnd, WM_CLOSE, 0,0), then confirm the process terminated. Regards Mike