KillApp

System function.

The KillApp function kills the specified application. Not available in WinTask Lite.

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.

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 (for instance, Notepad.exe or Notepad or NOTEPAD are valid <exe_name>). All the instances of the application are killed.

If the second parameter is 1, the application is killed immediately. If the second parameter is 0 and if the application cannot be killed after 60 secs, a confirmation dialog box is displayed. If the user does not click OK within 60 secs, the application is killed.

<user_name>, string, optional parameter. If specified, KillApp kills only the instances of the specified application which have been started by the user <user_name>.

Return value

Ret, numeric return code. 0 if the specified application has been killed successfully, 1 if the application has been killed after user confirmation.A negative value is returned if the application could not be killed and script execution stops (unless #IgnoreErrors=1). The possible negative return codes are -3 if the Kill has been cancelled by the user, -4 if the application could not be killed due to an denied access, -1 if the application could not be killed for any other reason.

Example code

 

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")

 

UseWindow("NOTEPAD.EXE|Notepad|",1)

SendKeys("<Alt <F4>>")

 

KillApp("notepad",1)