How do I kill an unresponsive process or task in Windows when it becomes completely unresponsive (window becomes a ligt grey, cursor a rotating blue ring)?
- Clicking
[X]
or trying to end process intaskmgr
has no effect [status is unresponsive]. - Task can't be killed using Process Explorer [
procexp
] or with any of the following:TaskKill /f /pid %pid% TaskKill /f /im %exec.exe%
Stop-Process -Force -Name $name
答案1
To end unkillable processes, use WMIC
[Windows Management Instrumentation Console] in cmd
or powershell
, replace the variables with the PID/name of the process to kill:
cmd
(variable:%pid%
):WMIC Process where ProcessID=%pid% delete
powershell
(variable:${name}
):WMIC Process where Name="${name}.exe" delete
答案2
You can give a try to use this code in a batch file :
@echo off
Mode 90,3 & color 0B
Title Killing All Applications with Status equal to NOT RESPONDING
Taskkill /f /FI "STATUS eq NOT RESPONDING"
pause
EDIT :
With Powershell you can do something like this :
Clear-Host
While ($True) {
$DateTime =$Null
$DateTime = (get-date).ToLocalTime().ToString("dd/MM/yyyy @ HH:mm:ss")
Try {
$Processes = Get-Process -EA Stop
$nProcesses = @($Processes | ? { $_.Responding -eq $false })
#$nProcesses
} catch {
Write-Error "Failed to query processes. $_"
}
if($nProcesses) {
foreach($nProcess in $nProcesses) {
$nProcess | select ID,Name, MainWindowTitle,Path
Stop-process -Force $nProcess
}
} else {
Write-host "$DateTime - No non-responding processes found" -ForegroundColor Yellow
}
Start-Sleep -s 300
}