Solved

How Can You Close Down An Exe Launched With ShellExecute?

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

14 Experts available now in Live!

Get 1:1 Help Now