Hitachi

JP1 Version 11 JP1/Script Description and Reference (For Windows Systems)


9.8.3 TerminateProcess (forcibly terminate a process)

Purpose

Forcibly terminates a process specified by process ID.

Syntax
TerminateProcess(ProcessId [, Code])
Arguments
ProcessId

Specify the process ID as a number or as a variable that stores this value.

This process ID is the value returned in the buffer argument of the GetProcessCount command.

In JP1/Script 06-00 and later versions, you can specify the _EXEC_ID_ reserved variable set at execution of the Exec or NetExec command. In this case, the GetProcessInfo command acquires process information for an executable file called by an Exec or NetExec command specified not to wait for completion of the executable file (Flag argument set to False).

Code

Specify the exit code for the process to be terminated. Write a number or a variable that stores this value.

When this value is omitted, 0 is assumed.

Description

The TerminateProcess command forcibly terminates a process specified by process ID. The command returns True on successful execution, or False if an error occurs.

True is always returned if there is no such process ID.

Notes
  • At execution of this command, a message is output to the application log at the Event Viewer. The event ID is 7.

    Output to the event log is suppressed when the parameter /NOEVLOG or /NOEVLOG(7) is set in the command line defined in the execution environment file or in the command line set in the registry.

  • Execute the script file as a user who has administrator permissions. For details, see 1.8.2 Command behavior. If you do not execute the script file as a user who has administrator permissions, you cannot terminate processes being executed by other users (but can forcibly terminate script processes).

Example
' Forcibly terminate all active "ABC" processes other
' than the "ABC" process that started first.
Dim pCnt, pIdBuff, seppId
pCnt = GetProcessCount("ABC", pIdBuff)
If  pCnt > 1  Then
  For  i = 2 To pCnt
    seppId = SeparateStr(pIdBuff, ";", i)
    TerminateProcess(seppId)
  Next
End If
JP1/Script version

Supported from JP1/Script 05-20.