Q:

Check how many of a program are running via batch

Is it possible to check how many of a program are running via a batch file?
I made a program to use for tab for a cause and this is the code:
:1
    timeout /t 2
    start chrome.exe
    start chrome.exe
    start chrome.exe
    start chrome.exe
    timeout /t 7
    taskkill /f /im chrome.exe
    goto :1
But this program sometimes open more than 4 copies of chrome before closing them, up to 8. Is there a command that I could use which will say how many of the program are open? kinda like the below:
@echo off 
    :1 
    start chrome.exe
    if "4 of chrome.exe are open" goto :2 else goto :1 
    :2 
    timeout /t 7
    taskkill /f /im chrome.exe
    timeout /t 2 
    goto :1 
I kept on getting errors saying that it is not formatted properly until I put in all the spaces where the code is, why do you have to do that?

A:

It's difficult to treat chrome's processes because it normally creates a separated process for each plug-in (add-on). But answering your question:

Is there a command that I could use which will say how many of the program are open?

Yes, you can see how many processes with same name are open at the moment:
tasklist|find /c "chrome.exe"
For using this within an if statement you can do the following:
for /f %%a in ('tasklist^|find /c "chrome.exe"') do (set chromeProcesses=%%a)
if "%chromeProcesses%" == "4" (do something...)

