• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

How to close another application?

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.
0
Free_OJ
Asked:
Free_OJ
1 Solution
 
AxterCommented:
There's a class on the following link, called CreateProcessMngr:
http://www.axter.com/faq/topic.asp?TOPIC_ID=24&FORUM_ID=4&CAT_ID=9&Topic_Title=How+to+launch+a+program+from+another+program+in+VC&Forum_Title=C%2FC%2B%2B

You can use this class to start up both DOS and Windows applications, and it has an easy method to close both types.
0
 
AxterCommented:
The class is listed at the bottom of the above link.
0
 
AxterCommented:
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);
cp.CloseApp();

This method will work on both DOS and Win programs.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
AssafLavieCommented:
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).
0
 
MichaelSCommented:
>TerminateProcess

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.
0
 
AlexVirochovskyCommented:
see
  Processes list and kill by name
http://www.codeguru.com/win32/ps.shtml
   HOWTO: Terminate an Application "Cleanly" in Win32
http://support.microsoft.com/support/kb/articles/Q178/8/93.ASP
(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...


0
 
Free_OJAuthor Commented:
Axter,
I'll try your method later.

MichaelS,
Exactly how would I send ctrl-c?


AlexVirochovsky,
>>Problem with this metod,
>>that all Dos apps have same name
How would that be a problem?
0
 
AlexVirochovskyCommented:
>>How would that be a problem?
Becouse you don't know what exectly apps, that you close
by name.

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now