End a process tree on the command line (Windows)

I need a team that will allow me to complete the process of the process tree.

For example, it notepad.exewas created by the explorer. How to terminate notepad.exein the process tree explorer.exe?

+7
source share
4 answers

Use taskkill/IM <processname.exe>/T

+6
source

Try the utility PsKill + PsList from Install PsTools .

pslist -twill provide you with a process tree (here you can find notepad.exewhich is the child process explorer.exe. Then you can use pskillto kill the process with the specified id.

+2
source
taskkill /F /IM notepad.exe

notepad.exe - notepad.exe foo.exe , , Windows .

You can use tasklistto get the identifier of the process you want to target, and then use taskkill/F/PID <PID>to kill it.

+1
source

You can currently 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 in an elegant 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 }
0
source

All Articles