[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
简单想了一下思路,本机测试通过,测试前在C盘建一个TEST的目录将script1与script2放入test目录
C_File2过程是用于生成另一个文件的 比如script1.cmd就是用if exist XX和echo XXX>script2.cmd检测script2。 同样的script2.cmd中的C_File2用于检测和生成script1.cmd. 此处节省时间没写。

--------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

GOTO S_LOOP

:END

TOP

返回列表