【发布时间】:2019-10-13 19:43:10
【问题描述】:
我正在随机冻结应用程序,虽然我可以使用批处理文件轻松结束未响应的任务,但我正在尝试诊断导致问题的应用程序。但是我不能引用已经被 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 "status eq 没有响应" 该命令的语法不正确。
C:\Users\razra\Desktop>wmic process where "ProcessID= get CommandLine, ExecutablePath , - 无效的别名动词。
【问题讨论】:
-
如果您尝试诊断导致问题的应用程序,您是否检查了事件查看器中的应用程序日志,它甚至有一个command line interface。
-
Set %processPID% = taskkill.exe /fi "status eq not responding"不能工作;看看这个吧:How to set commands output as a variable in a batch file -
事件查看器是我第一次使用。每当出现问题时,它往往会将您引导至 Windows 服务,它只是假设它是窗户破裂而不是其他东西破坏窗户。感谢您提供有关 CMD 变量的信息,它帮助我决定继续使用 powershell。
标签: batch-file cmd