【问题标题】:cmd - know if have multiple console processes with same name and taskkill themcmd - 知道是否有多个具有相同名称的控制台进程并将它们杀死
【发布时间】:2016-06-05 07:30:47
【问题描述】:

我在 cmd: tasklist /FI "session name eq console" 中使用来获取正在运行的控制台进程列表。 我需要知道是否有多个同名的进程并将它们杀死 感谢您的帮助

【问题讨论】:

  • taskkill /FI "SESSION Eq Console" 输入taskkill /?

标签: batch-file cmd


【解决方案1】:

【讨论】:

    【解决方案2】:

    您需要从tasklist command 输出中计算每个图像名称的出现次数,请参阅下一个批处理脚本注释代码 sn-p:

    @ECHO OFF
    SETLOCAL EnableExtensions
        rem remove all variables with ? prefix (question mark)
    for /F "tokens=1 delims==" %%G in ('2^>NUL set ?') do SET "%%~G="
        rem count
    for /F "skip=1 tokens=1 delims=," %%G in ('
           tasklist /FI "SESSIONNAME eq Console" /FO csv
                                              ') do set /A "?%%~G+=1"
        rem use counters
    for /F "tokens=1,2 delims=?=" %%G in ('2^>NUL set ?') do (
        if %%H GTR 1 (
                rem next echo for debugging purposes
            echo              %%G process counter = %%H
            if /I NOT "%%G"=="cmd.exe" (
                    rem taskkill command is merely displayed for debugging purposes
                ECHO taskkill /IM %%G
            ) else (
                    rem needs more elaborated code to avoid killing the script itself
                echo       retain %%G
            )
        )
    )
    

    输出:

    ==> D:\bat\SO\37639505.bat
                 chrome.exe process counter = 4
    taskkill /IM chrome.exe
                 cmd.exe process counter = 2
          retain cmd.exe
                 iexplore.exe process counter = 3
    taskkill /IM iexplore.exe
                 powershell_ise.exe process counter = 2
    taskkill /IM powershell_ise.exe
    
    ==>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多