How to close a another program within C++

I'm using the system call to run a program within my code but I want to be able to close that program after a few seconds. What happens is I call the prgram and it runs and takes over my screen but it's waiting for the user to hit the ESC key to exit the program so if I don't hit exit...it'll stay on that program screen and won't return control to my program. What I was wondering if there is a way to kill that program after it runs for a while.

I'm creating a console project and I used this to call the other program

If you have the handle to the program, you can try sending it a WM_QUIT message using SendMessage(). If you're executing the program using system, instead of CreateProcess, then you can attempt to get the program's handle by using FindWindow() (assuming you know the title of the window or its window class).

You can also use TerminateProcess!
But this is very unusual.
If you really want to "Shoot down" the program use it.
With the SendMessage program will behave as if user clicked x-icon.
WIth TerminateProcess it ends immediatly