KillApp – System Function






KillApp Function


Usage

The KillApp function kills the specified application. This function is not available in WinTask Lite.

Used to force an application (a program file or EXE) to close. The KillApp function is more powerful than the CloseWindow function as it closes the application even if it is not responding or if a Save dialog prevents it from closing.

Syntax

KillApp(<exe_name>,0|1 [,<user_name>])
or
ret = KillApp(<exe_name>,0|1 [,<user_name>])

Parameters

  • <exe_name>: string, name of the application to kill. The name of the application is not case sensitive and the extension is not compulsory (e.g., Notepad.exe, Notepad, or NOTEPAD are valid).
  • 0|1: integer, if 1, the application is killed immediately. If 0, a confirmation dialog box is displayed if the application cannot be killed after 60 seconds.
  • <user_name>: string, optional. If specified, KillApp kills only the instances of the specified application started by the user <user_name>.

Return Value

Ret, numeric return code. Possible values:

  • 0 if the application has been killed successfully.
  • 1 if the application has been killed after user confirmation.
  • A negative value if the application could not be killed (e.g., -3 if the kill was cancelled by the user, -4 if access was denied, -1 for any other reason).

Remarks

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

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(">")
'Kill Notepad immediately
KillApp("notepad", 1)