Hitachi

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


9.8.1 GetProcessCount (get the number of process activations)

Purpose

Gets the number of activations of a process.

Syntax
GetProcessCount(ProcessName [, ProcessIdBuff])
Arguments
ProcessName

Specify the process name as a character string or as a variable that stores this value.

Specify the process name without a folder name or an extension such as .EXE.

ProcessIdBuff

Specify a variable for storing the process ID(s).

In JP1/Script 06-00 and later versions, you can specify a dynamic one-dimensional array variable.

Omit this argument if not required.

When the process specified in ProcessName is activated concurrently from two or more calling processes, the process IDs are sorted in start order and stored in either of the following ways:

  • If you specify a variable in ProcessIdBuff, the process IDs are stored as a string delimited with semi-colons (;).

  • If you specify an array variable in ProcessIdBuff, the process IDs are stored in order from the first element. Afterwards, the size of the array variable is set to the number of process IDs.

Description

The GetProcessCount command gets the number of activations of a specified process. On successful execution, the command returns the process count. If you specify the ProcessIdBuff argument, the command also returns the process ID(s).

If the specified process has not been activated, the command returns zero and stores a zero-length string ("") in ProcessIdBuff. If an error occurs, a zero-length string ("") is returned.

Supplement
  • Due to a restriction in the Windows specifications, a complete name cannot be acquired for processes activated with a local system account. For this reason, the following problem occurs if the GetProcessCount command is executed from an account other than the system account by specifying the name of a process activated with the local system account: If the specified process name contains more than 15 characters (including the extension), the number of activations and the process ID(s) are not returned, even if the process is active.

    To avoid this situation, specify no more than the first 15 characters of the process name, including the extension, in ProcessName. For details, see Example 2.

  • Execute the script file as a user who has administrator permissions. For details, see 1.8.2 Command behavior.

    Important note

    Execute the script file as a user who has administrator permissions.

Example 1
' List the process IDs for process "ABC".
Dim pCnt, pIdBuff, seppId
pCnt = GetProcessCount("ABC", pIdBuff)
For  i = 1 To pCnt
  seppId = SeparateStr(pIdBuff, ";", i)
  Message(Target_File, _SCF_+"PIDLIST.TXT", seppId)
Next
Example 2
Dim  PLName, Pname, PnameWork, Rc, IdBuff
PLName ="ABCDEFGHIJKL"
Pname = "ABCDEFGHIJKL.exe"
' First execute with normal specification method
'(specify process name).
Rc = GetProcessCount(PLName, IdBuff)
' If number of activations is 0, execute
' processing that considers process is activated
' from local system account.
If Rc = 0 Then
    If Len(Pname)> 15 Then
        PnameWork = Left(Pname, 15)
    End If
    Rc = GetProcessCount(PnameWork, IdBuff)
End If
JP1/Script version

Supported from JP1/Script 05-20.