保持Y的X实例始终在运行,窗口

我怎样才能用批处理脚本确保我总是运行例如cmd.exe的X实例?

我search,发现如果X实例正在运行,这给了我X行。

tasklist /FI "IMAGENAME eq exe.exe" 2>NUL | find /I /N "exe.exe" 

然后,如果已经停止运行,请执行START XXX XSTART XXX X次…?

Solutions Collecting From Web of "保持Y的X实例始终在运行,窗口"

怎么样

 set PROG=exe.exe set COUNT=0 set WANT=5 for /f "skip=1" %%i IN ('wmic process where Name^="%PROG%" get Name') do ( if /i %%i equ %PROG% set /a COUNT+=1 ) echo count: %COUNT% set /a WANT-=COUNT if %WANT% gtr 0 for /l %%i in (1,1,%WANT%) do start %PROG%