--------Script 1------
@ECHO OFF
:Main
title Script1
SET S1=1
SET S2=1
:C_File1
If not exist c:\test\wait1.vbs echo WScript.Sleep 100 >c:\test\wait1.vbs
:C_File2
Rem here is use for create SCRIPT2.CMD
:S_LOOP
FOR /F %%i IN ('TASKLIST /v ^|FIND "Script1" /i /c') DO SET S1=%%i
IF /I %S1% GEQ 2 GOTO END
FOR /F %%i IN ('TASKLIST /v ^|FIND "Script2" /i /c') DO SET S2=%%i
IF /I %S2% GEQ 1 (
ECHO Running script 2 is %S2%
) ELSE (
ECHO script 2 is closed, rerun it
Start /min C:\test\script2.cmd
)
START /wait /MIN CSCRIPT.EXE C:\TEMP\Wait1.vbs
GOTO S_LOOP
:END
-----------Script 2------------
@ECHO OFF
:Main
title script2
SET S3=1
SET S4=1
:C_File1
If not exist c:\test\wait1.vbs echo WScript.Sleep 100 >c:\test\wait2.vbs
:C_File2
Rem here is use for create SCRIPT1.CMD
:S_Loop
FOR /F %%i IN ('tasklist /V ^|FIND "script2" /i /c') DO SET S3=%%i
IF /I %S3% GEQ 2 Goto END
ECHO Check MKFIRST is running...
FOR /F %%i IN ('tasklist /V ^|FIND "Script1" /i /c') DO SET S4=%%i
IF /I %S4% GEQ 1 (
ECHO Running script 1 is %S4%
) ELSE (
ECHO script 1 is closed, rerun it
Start /min C:\test\script1.cmd
)
START /wait /MIN CSCRIPT.EXE C:\TEMP\Wait2.vbs