0

I am having random Applications Freeze up, while I can easily end unresponded tasks with the batch file, I am trying to diagnose which applications are causing the problems. But I cannot Reference a task that has already been killed by PID. I would like the code to show offending Applications before or after killing the process.

This is what I've been using up till now, it does work and does show the PID. But it does not show the application name.

@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

This is what I get when running the new code

It appears that the variable processPID is not being set.

C:\Users\razra\Desktop>Set = taskkill.exe /fi "status eq not responding" The syntax of the command is incorrect.

C:\Users\razra\Desktop>wmic process where "ProcessID= get CommandLine, ExecutablePath , - Invalid alias verb.

Aksen P
  • 4,564
  • 3
  • 14
  • 27
  • 1
    If you're trying to diagnose which applications are causing the problems, have you checked the Application Logs in the Event Viewer, it even has a [command line interface](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/wevtutil). – Compo Oct 13 '19 at 20:18
  • `Set %processPID% = taskkill.exe /fi "status eq not responding"` can't work; take a look at this instead: [How to set commands output as a variable in a batch file](https://stackoverflow.com/q/6359820) – aschipfl Oct 14 '19 at 11:21
  • Event Viewer was my first go to. It tends to direct you toward windows services whenever something goes wrong it just assumes it is windows breaking and not something else breaking windows. Thank you for the info on CMD variables, it helped me in deciding to move on with powershell. – Raymond Euerle Oct 15 '19 at 17:41

1 Answers1

0

If you are willing to try PowerShell, you can achieve the same functionality.

  1. Loop trough the processes having Responding property false.
  2. Stops the process by ID.

    Foreach($proc in Get-Process | Where-Object {$_.Responding -eq $false}){
       Write-Host $proc.ID, $proc.Name
       Stop-Process $proc.ID
    }
    
  3. Save the code with ps1 extension and run with PowerShell.exe -File <path>
EylM
  • 5,967
  • 2
  • 16
  • 28