Board logo

标题: [系统相关] 批处理怎样检测同名进程个数 [打印本页]

作者: xymc    时间: 2015-11-3 23:18     标题: 批处理怎样检测同名进程个数

比如某机有时有一个QQ.exe,有时有2个,怎么样可以用bat检测有多少个QQ.exe,如果检测到只有一个就直接exit,如果有发现2个就执行start xxx.exe操作。
作者: CrLf    时间: 2015-11-3 23:50

  1. tasklist /fi "imagename eq qq.exe" | find /c /v ""
复制代码

作者: DAIC    时间: 2015-11-4 08:59

  1. @echo off
  2. for /f %%i in ('tasklist /fi "imagename eq QQ.exe" ^| find /c /i "QQ.exe"') do (
  3.     if %%i gtr 1 (
  4.         start "" "C:\xxx.exe"
  5.     )
  6. )
复制代码

作者: DAIC    时间: 2015-11-4 09:00

回复 2# CrLf


    tasklist 的结果里面还有标题和空行
作者: flyinnet9    时间: 2015-11-4 10:20

tasklist |find /c "QQ.exe"
作者: DAIC    时间: 2015-11-4 10:34

回复 5# flyinnet9


    这样不太严谨,因为其它进程也可能包含 QQ.exe 这个关键字。
作者: terse    时间: 2015-11-4 10:48

  1. tasklist /fo csv /nh /fi "imagename eq qq.exe" |find /v /c ""
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2