Identificar instâncias em execução de um arquivo em lotes

Estes não estão funcionando para mim.

Qualquer ajuda para definitivamente corrigir os quatro exemplos abaixo?

O EXAMPLE 01 apenas ecoa "continuar", mesmo se eu tiver três CMD.exe abertos.

---------- EXEMPLO 01 ------------

@echo off 
wmic process where name="cmd.exe" | find "cmd.exe" /c
SET ERRORLEVEL=value if "%value%" GTR 1 ( 
    ECHO This batch is not first  
    ECHO quitting ...
    )
if "%value%" LSS 2 ECHO continue

Estou recebendo a mensagem "i inesperado" no EXEMPLO 02!

----------- EXEMPLO 02 -------

@echo off
FOR /F "usebackq tokens=2" %i IN (`tasklist ^| findstr /r /b "cmd.exe"`)
   DO taskkill /pid %%i

Eu estou recebendo a mensagem "é a primeira" no EXEMPLO 03, mesmo com três CMD.exe abertos!

----------- EXEMPLO 03 -------

 @echo off
    wmic process where name="cmd.exe" | find "cmd.exe" /c
    if "%errorlevel%" LEQ 1 echo CMD is first
    if "%errorlevel%" GTR 1 echo CMD is already running

Também é possível que eu não tenha acesso ao comando Wmic no trabalho, portanto, outra possibilidade é encontrada no EXEMPLO 04 ... mas sem sucesso.

----------- EXEMPLO 04 -------

@echo off
Tasklist /FI "IMAGENAME eq cmd.exe" 2>NUL | find /I /N "cmd.exe">NUL
if "%ERRORLEVEL%"==0 do (goto Use) else (goto Cont)
:Cont
ECHO Only one instance running
pause

:Use
echo Application running already. Close this window

Atenciosamente, Maleck

questionAnswers(2)

yourAnswerToTheQuestion