我有随机的应用程序冻结,虽然我可以轻松地用批处理文件结束未响应的任务,但我正在尝试诊断是哪些应用程序引起了问题。但是我无法引用已经被PID终止的任务。我希望代码显示在终止进程之前或之后令人反感的应用程序。
这是我到目前为止一直在使用的,它确实有效并且确实显示了PID。但是它不显示应用程序名称。
@echo off
:Start
taskkill /f /fi "status eq not responding"
TIMEOUT /t 30 /nobreak
goto Start
**This is what i've been trying to use to get the offending application name**
:Start
Set %processPID% = taskkill.exe /fi "status eq not responding"
wmic process where "ProcessID=%processPID% get CommandLine, ExecutablePath
taskkill.exe /f /fi "status eq not responding"
TIMEOUT /t 5 /nobreak
goto Start
这是运行新代码时得到的信息
似乎没有设置变量processPID
。
C:\ Users \ razra \ Desktop> Set = taskkill.exe / fi“状态eq无响应”该命令的语法不正确。
C:\ Users \ razra \ Desktop> wmic进程,其中“ ProcessID =获取命令行,ExecutablePath,-无效的别名动词。
如果您愿意尝试PowerShell
,则可以实现相同的功能。
Responding
属性false
的进程。按ID停止进程。
Foreach($proc in Get-Process | Where-Object {$_.Responding -eq $false}){
Write-Host $proc.ID, $proc.Name
Stop-Process $proc.ID
}
ps1
扩展名保存代码并以PowerShell.exe -File <path>
运行