Solved

How to close another application?

Posted on 2001-06-14
9
209 Views
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.
0
Comment
Question by:Free_OJ
9 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 300 total points
ID: 6193979
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
 
LVL 30

Expert Comment

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

Expert Comment

by:Axter
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);
cp.CloseApp();

This method will work on both DOS and Win programs.
0
 
LVL 4

Expert Comment

by:AssafLavie
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).
0
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.

 
LVL 6

Expert Comment

by:MichaelS
ID: 6194390
>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
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6194529
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
 

Author Comment

by:Free_OJ
ID: 6195330
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
 
LVL 14

Expert Comment

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

0
 
LVL 30

Expert Comment

by:Axter
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.
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

Title # Comments Views Activity
Parsing XML instructions in Java/any other language.... 3 104
Grammars for C C++ and java 1 114
max float value 3 26
show out valin of json for debugging in visaul c++ 1 17
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 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

24 Experts available now in Live!

Get 1:1 Help Now