Sign in to follow this  
n0ob

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

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
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
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

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