这些对我没有用。
请帮忙确切地纠正以下四个示例吗?
即使我打开了三个CMD.exe,EXAMPLE01仅回显“continue”。
---------- 示例 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
我在EXAMPLE 02中收到了“意外的i错误”信息!
----------- EXAMPLE 02 -------
@echo off
FOR /F "usebackq tokens=2" %i IN (`tasklist ^| findstr /r /b "cmd.exe"`)
DO taskkill /pid %%i
我在EXAMPLE 03中即使打开了三个CMD.exe窗口,仍然会收到“is first”消息!
@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
我可能在工作中无法使用Wmic命令,因此在例子04中找到了另一个可能性...但并没有成功。
----------- 例子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
亲切的问候, Maleck