How to close another application?

Posted on 2001-06-14
Last Modified: 2008-02-01
My program starts several applications.
Some of them are DOS programs and some are windows.
When my program closes, I want to make sure that all the applications it started are closed.
How can I close them all?

Looking for a method to close both DOS and Windows Applications.

Please give example.
Question by:Free_OJ
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 30

Accepted Solution

Axter earned 300 total points
ID: 6193979
There's a class on the following link, called CreateProcessMngr:

You can use this class to start up both DOS and Windows applications, and it has an easy method to close both types.
LVL 30

Expert Comment

ID: 6193982
The class is listed at the bottom of the above link.
LVL 30

Expert Comment

ID: 6193992
The following example launches Turbo C++, then closes it.

CreateProcessMngr cp("E:\\Borland\\TC\\Bin\\tc.exe","E:\\Borland\\TC\\Bin\\",NULL,NULL,SW_NORMAL);

This method will work on both DOS and Win programs.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 6194220
When you create new processes, just keep the Handles to them in some sort of list, and when your program exists go over that list and kill that ones that are still active (TerminateProcess).

Expert Comment

ID: 6194390

is really not nice to use.

For windows apps I would suggest send WM_CLOSE message to main window (find it by FindWindowEx(), usually it should work. For dos app you can try "Ctrl + C" combination to be sent to the app window.

If apps you started is yours than it's defenetly better to organize some type of communication between it. I think the best is Events.
LVL 14

Expert Comment

ID: 6194529
  Processes list and kill by name
   HOWTO: Terminate an Application "Cleanly" in Win32
(for Windows.)
>>For dos app you can try "Ctrl + C"
Not all DOS apps reacts to "Ctrl + C"
Better use metod from 1-st link. Problem with this metod,
that all Dos apps have same name...


Author Comment

ID: 6195330
I'll try your method later.

Exactly how would I send ctrl-c?

>>Problem with this metod,
>>that all Dos apps have same name
How would that be a problem?
LVL 14

Expert Comment

ID: 6198305
>>How would that be a problem?
Becouse you don't know what exectly apps, that you close
by name.

LVL 30

Expert Comment

ID: 6198506
With the CreateProcessMngr class in the above link, you don't need the name.
The class will close only the program launched by it.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

717 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