Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do You Start And Stop An External Program?

Status
Not open for further replies.

TBaz

Technical User
Jun 6, 2000
65
0
0
ES
I have a Delphi program where you select a program - ie Calculator, Notepad etc.

A 'Start' button launches the program you selected (let's say it's Calculator).

When you click on the 'Stop' button which closes the Calculator.

This needs to work regardless of the program chosen by the user.

At first, I thought this would be fairly straight forward.

Using ShellExecute the external program launches fine. The problem is stopping it from running.

There's also PostMessage for closing an application, but when you launch a program with ShellExecute there doesn't seem to be any way of finding out what handle the app is using for the PostMessage function.

Anyone give me some pointers on what I'm doing wrong please or suggest an alternative method?

TBaz
 
ahum, you create a process using CreateProcess, and you'll get the handle to that process. That handle can be used to Terminate the process.

Bobbafet, if you read the posts carefully, the original question was : I want to start an external app from the delphi app and I want to kill that app from the delphi app.

I gave the solution to this problem so please consider this thread as closed.

Thank you,
Daddy

[soapbox]

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Yes I have read it carefully, but what happens if two instances are started of Notepad for example? How can findwindow tell which one it is that the user wants to close? And that is what I am getting at, this is fine if there will be only 1 instance of each program EVER, there's no telling which one will be closed if there is 2 instances of them.

Read mine carefully too.

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
BobbaFet, whosrdaddy's solution doesn't use FindWindow. You have pointed out where the technique that Aaron highlighted comes unstuck.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
I see it now, mustve have missed it somehow, my bad...

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
Case closed! ;-)

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top