Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Terminate External Program 1

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
US
Hi,
When I press the terminate key on my program I need to check and see if another specific program is running and terminate it.

Any ideas on how to do this would be appreciated.
 
This task is easy if your application Spawned/Shelled the other application with the CreateProcess API function.

If your application did NOT launch the other executable, then You need to get a Handle to the other program's main window. (This is where the WindProc resides).

Once you have this handle, you can basically make the other application do anything you want (by sending windows messages).

A few API calls to look into when doing this:

EnumWindows
GetWindowText
PostQuitMessage

If this doesn't help, there's probably another way ... there always is.




 
You'll need to hook the other application and from there you can terminate it. The code is too long to display here. If you search for how-tos on hooking other applications, you'll probably find out how. I know I saw an example on under the C/C++ section, try searching their website for "Hook" and "Title Bar" that code should point you in the right direction.

Also, I recall an article in "C++Builder Developer's Journal" just a little while back. I know they posted a zip of the code on it. Try downloading their zips for 2002. I pretty sure they have an example of what you want in there somewhere. Once I get some time, I'll try and find it for you. Cyprus
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top