PsKill - CMD


Overview

PsKill is a command-line utility for terminating processes on local or remote systems. Its primary purpose is to forcefully stop processes that may not terminate after standard closing procedures fail, making it particularly useful for system administration, automated batch jobs, and process management in scripts.

Syntax

pskill [-t] [-accepteula] [-?] [-] [\\computer [-u user [-p passwd]]] {<process ID | process name>}

Parameters:

  • <process ID | process name>: Specifies the target process by its ID or name.

Optional Parameters:

  • \\computer: Specifies the computer on which the target process is running. If omitted, PsKill targets the local system.
  • -u user: Specifies the process should act with the authority of the user account specified.
  • -p passwd: Specifies the password for the user account specified with -u.

Options/Flags

  • -t: Kills the specified process and all of its child processes.
  • -accepteula: Automatically accepts the Sysinternals license agreement for automated use.
  • -?: Displays help at the command prompt.

Examples

Example 1: Terminating a process by its ID

Terminate a process with a specific ID on the local machine:

pskill 1234

Example 2: Terminating a process by name

Stop all instances of “notepad.exe” on the local system:

pskill notepad.exe

Example 3: Terminating processes on a remote machine

Terminate all “firefox.exe” processes on a remote machine named “Server01”:

pskill \\Server01 firefox.exe

Example 4: Using user credentials

Terminate a process on a remote system using specified user credentials:

pskill \\Server01 -u admin -p password1234 5678

Common Issues

  • Access Denied: Without proper permissions, PsKill will return an “Access Denied” error. Ensure administrator rights or correct user credentials for remote systems.
  • Process Not Found: If the process name or ID does not exist, check for typos or confirm the current running processes.
  • Network Issues: When operating on remote systems, network issues can prevent PsKill from connecting. Verify network connectivity and permissions.

Integration

PsKill can be used in scripts to automate the cleanup of stalled or non-responsive processes. For example, integrating PsKill with a batch file that checks for the existence of a process and terminates it if it has been running for too long.

@echo off
for /f "tokens=2" %%i in ('tasklist /nh /fi "imagename eq notepad.exe"') do set pid=%%i
pskill %pid%
  • Taskkill: Similar to PsKill, it is used to kill tasks by process ID or image name, but has more options and is included with Windows by default.
  • PsList: Displays detailed information about processes, which can be useful to determine which processes to target with PsKill.

Additional resources can be found on the Sysinternals website, where the latest versions and documentation for PsKill and related tools are maintained.