• Advertisement
Sign in to follow this  

C++ Win32: Closing process with handle from ShellExecute..

This topic is 4946 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to close an EXE that I run from another program. The first program opens the second one with ShellExecute, and I store the handle: HINSTANCE hserv = ShellExecute(0,"open","server.exe",params,0,SW_SHOWMINNOACTIVE); Then, I wish to close it later. I was wondering what function to use. I have tried a few already, but they just aint' workin :P Thanks for any info! [Edited by - n0ob on August 4, 2004 10:49:44 AM]

Share this post


Link to post
Share on other sites
Advertisement
Look into CloseHandle and CreateProcess. CreateProcess might be better for you if you are launching child programs from your program.

Easiest way to do close a program would probably be...

SendMessage(handle, WM_CLOSE, 0, 0); // WM_CLOSE / WM_DESTROY
/ ...
Hope that helped

Share this post


Link to post
Share on other sites
Yeeeahh... ShellExecute returns an HINSTANCE, ... And I really don't want to figure out how to use CreateProcess. I don't see a way to store a handle to what I'm creating.. or whatever.. I obviously don't know enough about that. There has to be a simpler way. THis shouldn't be a hard question people o_^

Share this post


Link to post
Share on other sites
Also, the program executed at run time is a console application. Maybe if someone told me how to get an HWND handle to a console's window :D

Share this post


Link to post
Share on other sites
woohoo! I found the function to set the console title!! lol, well, I'll use this for now, it seems to work for me and FindWindow. Tahnks!

Share this post


Link to post
Share on other sites
CreateProcess returns the process handle in the PROCESS_INFORMATION object you give it. Then you can simply use CloseHandle with that handle to kill the process.

Share this post


Link to post
Share on other sites
You can also use ShellExecuteEx to start the program and get the process handle to it. ShellExecute does not return a handle of any use (other than to test for an error condition).

Share this post


Link to post
Share on other sites
Ihad a similiar problem when I wanted to spawn a console app, then wait until it quits. I gave in and switched from ShellExecute to CreateProcess (as nts suggests) and it all works great now.

I suggest you bite the bullet and do the same.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement