14

I am in need of a command that will allow me to terminate a process of a process tree.

For example notepad.exe was created by explorer. How would I terminate the notepad.exe in the explorer.exe process tree ?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Peter
  • 141
  • 1
  • 1
  • 3

5 Answers5

9

This answer is not exactly for this case, but it can be useful for people looking how to kill the whole process tree. We need to combine some answers here to get the proper result: kill the process tree and force it.

taskkill /IM "<process-name>" /T /F

For some processes you need to run the command in a console application with administrator rights.

Tonatio
  • 4,026
  • 35
  • 24
6

Use taskkill /IM <processname.exe> /T.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Alois Kraus
  • 13,229
  • 1
  • 38
  • 64
4

Nowadays, you can do this with PowerShell:

$cimProcesses = Get-CimInstance -Query "select ProcessId, ParentProcessId from Win32_Process where Name = 'notepad.exe'"
$processes = $cimProcesses | Where-Object { (Get-Process -Id $_.ParentProcessId).ProcessName -eq "explorer" } | ForEach-Object { Get-Process -Id $_.ProcessId }

$processes.Kill()

Or the graceful way:

$cimProcesses = Get-CimInstance -Query "select ProcessId, ParentProcessId from Win32_Process where Name = 'notepad.exe'"
$cimProcesses = $cimProcesses | Where-Object { (Get-Process -Id $_.ParentProcessId).ProcessName -eq "explorer" }

$cimProcesses | ForEach-Object { taskkill /pid $_.ProcessId }
Gama11
  • 31,714
  • 9
  • 78
  • 100
Rosberg Linhares
  • 3,537
  • 1
  • 32
  • 35
3
taskkill /F /IM notepad.exe

This would kill all notepad.exe's -- if you want a way to specify to only kill notepad.exe's which were created by foo.exe or so, I do not think Windows command lines are powerful enough for this.

You might can use tasklist to get the process ID of the process you want to target and then use taskkill /F /PID <PID> to kill it.

Gama11
  • 31,714
  • 9
  • 78
  • 100
Ben
  • 2,867
  • 2
  • 22
  • 32
2

Try PsKill + PsList utilities from the PsTools set.

pslist -t will give you a process tree (here you can find notepad.exe which is a child process of the explorer.exe. Then you can use pskill to kill the process with specified id.

Kirill V. Lyadvinsky
  • 97,037
  • 24
  • 136
  • 212