Solved

How Can You Close Down An Exe Launched With ShellExecute?

Posted on 2003-11-11
2
368 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now