如何算当前运行具有相同名称的过程量,使用批处理文件 [英] How to count amount of processes with identical name currently running, using a batchfile
问题描述
我想用一个批处理文件来比较名为standard.exe过程中,被我的Windows 7计算机上运行的数量,用名为basic.exe的进程数。如果过程被称为standard.exe额等于叫basic.exe什么应该发生过程中的量,如果数字不相等,basic.exe应重新启动。
I would like to use a batch file to compare the number of processes named "standard.exe", that are running on my Windows 7 machine, with the number of processes named "basic.exe". If the amount of processes called "standard.exe" equals the amount of processes called "basic.exe" nothing should happen, if the numbers are unequal, basic.exe should be restarted.
任何想法?已发现以下code,检查进程是否正在运行,但现在我想算携带相同名称的进程数。
Any ideas? Already found the following code to check whether a process is running, but now I would like to count the number of processes carrying the same name.
tasklist /FI "IMAGENAME eq myapp.exe" 2>NUL | find /I /N "myapp.exe">NUL
if "%ERRORLEVEL%"=="0" echo Programm is running
在此先感谢!
推荐答案
如果你不想写一个文件,替换任务列表
并设置 VAR1
与
If you don't want to write a file, replace the tasklist
and set var1
commands with
for /f "tokens=1,*" %%a in ('tasklist ^| find /I /C "standard.exe"') do set var1=%%a
同样的第二人。
for /f "tokens=1,*" %%a in ('tasklist ^| find /I /C "basic.exe"') do set var2=%%a
这篇关于如何算当前运行具有相同名称的过程量,使用批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!