Kill Process
Kill Process
Section titled “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.
How it works
Section titled “How it works”- 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,pidwins. - Each process is terminated together with its child processes, and the activity waits up to
timeoutms 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 = truethose 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.
Required parameters
Section titled “Required parameters”None. But you must set name or pid.
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | — | Process name, with or without .exe (e.g. "invoicing"). Every process with that name is terminated. |
pid | int | — | Process id (e.g. the output of Open App). Use it instead of the name to terminate a single process. |
allSessions | bool | false | Also terminate processes in other Windows sessions (other users or robots on the same machine). |
timeout | int | 10000 | Milliseconds to wait for each process to exit. An empty, 0 or negative value uses 10000. |
Output
Section titled “Output”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).
Common errors
Section titled “Common errors”| Message | Cause 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” error | The 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. |
Example
Section titled “Example”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: pidTerminate only the instance the robot itself opened:
Open App path = "C:/Programs/Invoicing/invoicing.exe" → output: pid... work ...Kill Process pid = pidRelated activities
Section titled “Related activities”- Open App — open the application again.
- Take Screenshot — keep evidence of what was on screen.
- Win Close — close a window in an orderly way.
- Try / Catch — handle the error that led to the recovery.