How can I kill a process which is started by ShellExecute() in Delphi 7. When clicking a button a java application is opened. It works perfectly. I need to close the process by clicking another button. How can I terminate the java application from delphi?
-
possible duplicate of I have the Process ID and need to close the associate process programatically with Delphi 5Ken White– Ken White2011-06-17 11:01:46 +00:00Commented Jun 17, 2011 at 11:01
-
3@Ken In this case it is going to be easier to get the process handle as the process is created rather than hunting around for a process handle.David Heffernan– David Heffernan2011-06-17 11:05:31 +00:00Commented Jun 17, 2011 at 11:05
-
possible duplicate of Delphi - Gracefully Closing Created Process in Service. (using tprocess / createProcess)Rob Kennedy– Rob Kennedy2011-06-17 14:17:34 +00:00Commented Jun 17, 2011 at 14:17
Add a comment
|
1 Answer
In this case you would be better to use ShellExecuteEx() to start the process. This allows you to obtain the newly created process handle which is not returned by ShellExecute. Once you have that you simply call TerminateProcess. As yet another alternative, you may consider creating the process with CreateProcess.