Solved

How Can You Close Down An Exe Launched With ShellExecute?

Posted on 2003-11-11
2
369 Views
Last Modified: 2010-04-05
I launch an external program in the Form Create section of my app with:

ShellExecute(0, 'Open', PChar('Other.exe'), PChar(''), PChar(''), SW_Hide);

This works perfectly, but I just found out that there were approximately 30 instances of this program running when I looked in the task manager!  Obviously, each time I run my app, another copy of the external program is run. :)

Is there any way of closing down a program launched in this way when I close my app down?

TDK_Man
0
Comment
Question by:tdk_man
2 Comments
 
LVL 2

Accepted Solution

by:
SaLz earned 100 total points
ID: 9727344
this will work for you :)

procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(FindWindow(Nil, 'Untitled - Notepad'), WM_QUIT, 0, 0);
end;

or

procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(FindWindow(Nil, 'Untitled - Notepad'), WM_QUIT, 0, 0);
ShellExecute(0, 'Open', PChar('Other.exe'), PChar(''), PChar(''), SW_Hide);
end;
0
 
LVL 1

Author Comment

by:tdk_man
ID: 9727671
Thanks!

It's one of those things you forget to remember...

TDK_Man
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question