how to close external application

Blitz3D Forums/Blitz3D Programming/how to close external application

vivaigiochi(Posted 2011) [#1]
Suppose i call an external application from my program, how i can close it when i want (for example if i open internet explorer how close the window with process?)


Adam Novagen(Posted 2011) [#2]
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskkill.mspx?mfr=true

Blitz can access any program that can be reached from the command prompt - like taskkill - using ExecFile. For example, this program:

Write "Terminating in 3... "
Delay 1000
Write "2... "
Delay 1000
Print "1..."
Delay 1000

ExecFile "taskkill /F /IM blitzcc.exe"

Print "Waiting to exit..."

Repeat Forever

"blitzcc.exe" is the process for Blitz programs, so basically this program just kills itself. It demonstrates usage pretty neatly though.

Two things here: one is that you will, of course, need to know the exact name of the process you're trying to close (the Processes tab in the Task Manager will help you there). The other is that, as you can see, this unfortunately makes a DOS prompt window pop up and disappear again, for running taskkill. This can't be avoided, but it's about as good as you'll get in Blitz, to my knowledge.

EDIT: In case you're wondering, this command also exists on Windows Vista and Seven. Not sure about pre-XP releases, but I'd guess it goes back to Windows NT at the very least.

Last edited 2011