【问题标题】:为什么 taskkill in batch 不适合我?
【发布时间】:2022-01-21 16:22:17
【问题描述】:

我试图杀死 GTA 5,但它没有响应,但是当我运行批处理文件时,它显示“成功:向 PID 3220 的进程发送终止信号。”,但它并没有停止它。

taskkill /fi "imagename eq GTA5.exe" /fi "status eq Not Responding"

如果任务没有响应,我也尝试使用任务列表并从中提取,但我不知道如何。

【问题讨论】:

  • 阅读消息:它说,它成功地向进程发送了终止信号,而不是它成功终止了进程。某些进程不会对该信号采取行动(因为它没有被编程为这样做,或者因为该进程不再能够这样做)。您可以尝试/f(强制)参数,但即使这样也不能保证有效。
  • 我们还需要更多信息。一般玩这种游戏的人不会直接运行它们,他们是从 Steam 运行并使用启动器的。当这些东西被引入时,有许多依赖项构成了游戏运行的一部分,它们可以有效地锁定/保持正在运行的可执行文件。我还要求您先向我们提供以下命令行的输出:%SystemRoot%\System32\tasklist.exe /Fi "ImageName Eq GTA5.exe" /Fo "CSV" /V%SystemRoot%\System32\wbem\WMIC.exe Process Where "Name='GTA5.exe'" Get /Format:'CSV'

标签: batch-file taskkill


【解决方案1】:

你可以试试这个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
}

【讨论】:

    猜你喜欢
    • 2014-01-03
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多