Sign in to follow this  
n0ob

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

Recommended Posts

n0ob    176
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
nts    968
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
n0ob    176
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
n0ob    176
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
n0ob    176
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
Mastaba    761
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
Mastaba    761
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
iMalc    2466
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this