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 ?
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With