'Why isn't taskkill in batch working for me?
I'm trying to terminate GTA 5 when it doesn't respond, but when I run the batch file, it says :
"SUCCESS: Sent termination signal to the process with PID 3220."
But it doesn't stop it.
taskkill /fi "imagename eq GTA5.exe" /fi "status eq Not Responding"
I also tried to use tasklist and extract from it if the task isn't responding, but I didn't find out how.
Solution 1:[1]
You can give try for this Embed PowerShell code in a batch file
@echo off
@REM https://martin77s.wordpress.com/2018/01/25/embed-powershell-code-in-a-batch-file/
@Title Get And Kill No Responding Processes
@setlocal EnableDelayedExpansion
@set LF=^
@SET command=#
@FOR /F "tokens=*" %%i in ('findstr -bv @ "%~f0"') DO SET command=!command!!LF!%%i
@powershell -noprofile -noexit -command !command! & goto:eof
# *** POWERSHELL CODE STARTS HERE *** #
While ($True) {
$DateTime = $Null
$DateTime = get-date
Try {
$Processes = Get-Process -EA Stop
$nProcesses = @($Processes | Where { $_.Responding -eq $false })
} catch {
Write-Error "Failed to query processes. $_"
}
if($nProcesses) {
foreach($nProcess in $nProcesses) {
$nProcess | select ID,Name, MainWindowTitle,Path
Stop-process -Force $nProcess
}
} else {
#Clear-Host
Write-host "$DateTime - No non-responding processes found" -ForegroundColor Yellow
}
Start-Sleep -s 60
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hackoo |
