Home > Language Reference > System Functions > KillApp

KillApp

The KillApp function kills the specified application.

Usage

Used to force an application (a program file or EXE) to close. KillApp function is more powerful than CloseWindow function as it closes the application even if it is not responding or if a Save dialog prevents from closing. KillApp function closes all the instances of an application (for example, all the Internet Explorer windows).

Syntax

ret = KillApp(<application_name>, 0|1 [, <userid>])

Parameters

<application_name>. string, name of the application to kill (a .EXE, case insensitive). The extension can be omitted. All the instances of the application are killed.

0|1. If 1, the application is killed immediately. If 0, a confirmation dialog box is displayed; after 60 seconds, the application is killed.

<userid>, string. If specified, KillApp kills only the instances of the specified application which have been started by <userid>.

Return value

ret, optional integer return value. If the application has been killed successfully, the return value is 0. If the application has been killed successfully after the user confirmation, the return value is 1. If the function fails, the return value is a negative value (see System Functions Error Codes).

Remarks

If you use KillApp to kill all the instances of Internet Explorer, the next time you open IE, you will get the message "Your last browsing session closed unexpectedly". To avoid this message, in the Tools menu of Internet Explorer, select Internet options and click the Advanced Tab. Under Browsing session, uncheck "Enable automatic crash recovery".

See also

KillAppChildren
KillProcess

Example

'The script below launches Notepad, types some text and exits. A dialog box is displayed asking if the document has to be saved.
'As KillApp is used with the 1 flag, the application Notepad is killed immediately.
Shell("notepad",1)
UseWindow("NOTEPAD.EXE|Edit||1",1)
SendKeys("Hello")
'Exit notepad
UseWindow("NOTEPAD.EXE|Notepad|",1)
SendKeys("<Alt <F4>>")
'Kill notepad immediately
KillApp("notepad",1)