需要通过使用批处理文件更改PID来获取进程名称

问题描述 投票:0回答:1

我有随机的应用程序冻结,虽然我可以轻松地用批处理文件结束未响应的任务,但我正在尝试诊断是哪些应用程序引起了问题。但是我无法引用已经被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,-无效的别名动词。

batch-file cmd
1个回答
0
投票

如果您愿意尝试PowerShell,则可以实现相同的功能。

  1. 循环通过具有Responding属性false的进程。
  2. 按ID停止进程。

    Foreach($proc in Get-Process | Where-Object {$_.Responding -eq $false}){
       Write-Host $proc.ID, $proc.Name
       Stop-Process $proc.ID
    }
    
  3. ps1扩展名保存代码并以PowerShell.exe -File <path>运行
© www.soinside.com 2019 - 2024. All rights reserved.