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 !
Printable View
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 !
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 !
Hi, check out this article.
http://www.codeproject.com/KB/thread...ProcessEx.aspx
Kevin Choong
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.
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.
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.
Just look for CreateProcess in MSDN or Google it.
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.
This should make the running app to quit after running for 5 seconds.Code:int iWaitSecond = 5;
WaitForSingleObject( processInformation.hProcess, 1000*iWaitSecond );
btw, fopen() is used to open a file, not to execute a file.
Hope this helps. :)
Kevin Choong
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 );
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
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.
Not to my knowledge. That's the limitation of using system commands.Quote:
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 ?
Using system commands, it would need to be something likeQuote:
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 );
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).
sweet. thanks for the answers Speedo !
I'll look into the other methods.
really appreciate the help.
cheers.
one question....
what's the " IM " for ?
thanks