Skip to content

Kill Process

Type: kill-process  ·  Package: Desktop Activities v1.0.8  ·  Output: int

Since: v1.0.3

Terminates Windows processes by name or by PID. It is the recovery piece for a system error: an application that hung, or that shows a dialog that won’t close, is terminated so it can be opened again cleanly with Open App. It returns how many processes it terminated.

  • By name (name): terminates every process with that name, written with or without .exe ("invoicing" or "invoicing.exe").
  • By PID (pid): terminates a single process, for example the one Open App returned. If you set both, pid wins.
  • Each process is terminated together with its child processes, and the activity waits up to timeout ms for each one to go away before moving on.
  • Only in the robot’s session: by default it only touches processes in the Windows session the robot runs in, so it never closes those of another person or another robot on the same server. Processes in other sessions are left running and the log says how many. With allSessions = true those are terminated too.
  • It never terminates itself (the robot’s process).
  • Idempotent: if no process has that name or PID, it is not an error: it returns 0. You can always place it before opening the application.

None. But you must set name or pid.

ParameterTypeDefaultDescription
namestring—Process name, with or without .exe (e.g. "invoicing"). Every process with that name is terminated.
pidint—Process id (e.g. the output of Open App). Use it instead of the name to terminate a single process.
allSessionsboolfalseAlso terminate processes in other Windows sessions (other users or robots on the same machine).
timeoutint10000Milliseconds to wait for each process to exit. An empty, 0 or negative value uses 10000.

Returns an int with the number of processes terminated. It is 0 if none was running (or if all of them were in other sessions and allSessions = false).

MessageCause and fix
Set 'name' or 'pid' to know which process to terminate.Both parameters are empty (or pid is not a number). Set one of them.
The process (PID …) did not exit within … ms.Windows did not finish closing the process within timeout. Raise timeout or retry with a Retry.
Windows “access denied” errorThe process runs as administrator or as another user and the robot’s account cannot terminate it. Run the robot with an account that has that permission.

Recover a hung application: keep evidence, terminate it and open it again cleanly.

Try / Catch errorVariable = error
├─ try:
│ ... steps on the application ...
└─ catch:
Take Screenshot path = pathJoin(str(Config["CarpetaCapturas"]), "error.png") → output: capture
Kill Process name = str(Config["ProcesoAplicacion"]) → output: closed
Log message = "Processes terminated: " + closed + ". Screenshot: " + capture
Open App path = str(Config["RutaAplicacion"]) → output: pid

Terminate only the instance the robot itself opened:

Open App path = "C:/Programs/Invoicing/invoicing.exe" → output: pid
... work ...
Kill Process pid = pid