-
February 10th, 2009, 03:51 AM
#1
How Can I Close exe files with C++ code ?
Hi,
I'm really new to C++.
Can someone please tell me the easiest way to close running exe files with C++ code ?
and then re-start the exe file later in the code ?
thanks a million !
-
February 10th, 2009, 05:08 PM
#2
Re: How Can I Close exe files with C++ code ?
anyone ??
I want my program to open windows calculator... and also close it later in the program.
can someone help me with this ? I'm sure with C++ it's a simple thing, yet I can't find anything
good on the subject of starting and closing exe files with your C++ program.
if anyone could even steer me to a good tutorial or article that would be great too.
better yet a short code example.
Thanks in advance !
-
February 11th, 2009, 01:46 AM
#3
Re: How Can I Close exe files with C++ code ?
-
February 11th, 2009, 01:57 AM
#4
Re: How Can I Close exe files with C++ code ?
You can use CreateProcess Or ShellExecute APi to launch the program and then use SendMessage(WM_CLOSE) to the main window of that app to ask it to get closed Or call TerminateProcess APi to kill it.
Regards,
Ramkrishna Pawar
-
February 11th, 2009, 02:08 AM
#5
Re: How Can I Close exe files with C++ code ?
hey thanks Kevin.
Looks way more complicated than I was hoping for. I will definately read it all though.
isn't there a way to use
fopen("myFileName.exe")
or something more simple ?
Thanks.
-
February 11th, 2009, 02:11 AM
#6
Re: How Can I Close exe files with C++ code ?
hey thanks Krishnaa,
can you give me a code example ?
I want to open calculator.exe,
then have a few more un-related functions take place,
then have the code close calculator.exe before the end of the program.
thanks.
-
February 11th, 2009, 02:28 AM
#7
Re: How Can I Close exe files with C++ code ?
Just look for CreateProcess in MSDN or Google it.
Regards,
Ramkrishna Pawar
-
February 11th, 2009, 02:59 AM
#8
Re: How Can I Close exe files with C++ code ?
The article I pointed to you is using CreateProcess, and one of the ways to signal a running program to quit is to modify the WaitForSingleObject.
Code:
int iWaitSecond = 5;
WaitForSingleObject( processInformation.hProcess, 1000*iWaitSecond );
This should make the running app to quit after running for 5 seconds.
btw, fopen() is used to open a file, not to execute a file.
Hope this helps.
Kevin Choong
-
February 11th, 2009, 03:28 AM
#9
Re: How Can I Close exe files with C++ code ?
cool, thanks Kevin.
that's exacty what I meant....
how do I find out the what to put in for " processInformation.hProcess " ?
Code:
int iWaitSecond = 5;
WaitForSingleObject( ? , 1000*iWaitSecond );
-
February 11th, 2009, 07:53 AM
#10
Re: How Can I Close exe files with C++ code ?
The processInformation is a structure object of PROCESS_INFORMATION.
It is filled in by the CreateProcess function with information about a newly created process (in your case the Calculator program).
Kevin Choong
-
February 11th, 2009, 08:46 AM
#11
Re: How Can I Close exe files with C++ code ?
Originally Posted by Jeff++
hey thanks Kevin.
Looks way more complicated than I was hoping for. I will definately read it all though.
isn't there a way to use
fopen("myFileName.exe")
or something more simple ?
Thanks.
You can do
system("calc");
but IIRC once that executes your program will be blocked until the user closes the calculator.
-
February 11th, 2009, 05:04 PM
#12
Re: How Can I Close exe files with C++ code ?
thank you Speedo !
that's what I wanted....
now is there a way to unblock the rest of the code in the program with the calculator still open ?
and how can I use C++ code to close the calc again.
what is the syntax for close window ?
would it be like system ( close.window );
or something to that effect ?
thanks everyone for the awsome help... I seem to learn much faster from live examples like this than eyeball-drying tutorials..
cheers.
-
February 11th, 2009, 08:57 PM
#13
Re: How Can I Close exe files with C++ code ?
that's what I wanted....
now is there a way to unblock the rest of the code in the program with the calculator still open ?
Not to my knowledge. That's the limitation of using system commands.
and how can I use C++ code to close the calc again.
what is the syntax for close window ?
would it be like system ( close.window );
Using system commands, it would need to be something like
system("taskkill /IM calc.exe");
However, it's irrelevant here because your program is not going to continue execution until calc is closed anyway. To get the kind of control you're asking for you'll have to use more complex methods (see the first few replies).
-
February 11th, 2009, 11:11 PM
#14
Re: How Can I Close exe files with C++ code ?
sweet. thanks for the answers Speedo !
I'll look into the other methods.
really appreciate the help.
cheers.
-
February 11th, 2009, 11:18 PM
#15
Re: How Can I Close exe files with C++ code ?
one question....
what's the " IM " for ?
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|