C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 7th, 2003, 03:00 PM
blue350z blue350z is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 1 blue350z User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to close a another program within C++

I'm using the system call to run a program within my code but I want to be able to close that program after a few seconds. What happens is I call the prgram and it runs and takes over my screen but it's waiting for the user to hit the ESC key to exit the program so if I don't hit exit...it'll stay on that program screen and won't return control to my program. What I was wondering if there is a way to kill that program after it runs for a while.

I'm creating a console project and I used this to call the other program

system("C:\\program.exe");

Reply With Quote
  #2  
Old February 7th, 2003, 03:03 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 55 m 33 sec
Reputation Power: 797
If you have the handle to the program, you can try sending it a WM_QUIT message using SendMessage(). If you're executing the program using system, instead of CreateProcess, then you can attempt to get the program's handle by using FindWindow() (assuming you know the title of the window or its window class).

Hope this helps!

Reply With Quote
  #3  
Old February 10th, 2003, 08:43 AM
MaierMan's Avatar
MaierMan MaierMan is offline
Titles are useless ;)
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Germanski West
Posts: 216 MaierMan User rank is Corporal (100 - 500 Reputation Level)MaierMan User rank is Corporal (100 - 500 Reputation Level)MaierMan User rank is Corporal (100 - 500 Reputation Level)MaierMan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 57 m 4 sec
Reputation Power: 9
Send a message via ICQ to MaierMan Send a message via AIM to MaierMan Send a message via MSN to MaierMan
You can also use TerminateProcess!
But this is very unusual.
If you really want to "Shoot down" the program use it.
With the SendMessage program will behave as if user clicked x-icon.
WIth TerminateProcess it ends immediatly

Reply With Quote
  #4  
Old February 10th, 2003, 12:24 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
TerminateProcess() would shutdown the program quite unclean. eg. it leave dlls open in memory. Avoid it if you can. But for a hanging program, it is often the only way.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > How to close a another program within C++


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway