欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

windows bat

程序员文章站 2022-05-08 13:07:53
...
@echo off
:begin

set SERVER_RUN_FLAG=''


:start
    echo %SERVER_RUN_FLAG%
    if %SERVER_RUN_FLAG%=="true" (
      echo result is true
      del /s /q /f C:\Users\user\server_status.txt
      exit /b 0
    ) else (
        TIMEOUT /T 3
        cd  C:\Users\user
        sc.exe query LanmanServer >> server_status.txt

        set TARGET_STR="RUNNING"

        set temp=''
        setlocal enabledelayedexpansion
        for /f  "delims=" %%i  in  (server_status.txt)   do (
            set temp=%%i
            echo !temp! | findstr %TARGET_STR% >nul && (set SERVER_RUN_FLAG="true")
        )
        if %SERVER_RUN_FLAG%=="true" (
          echo result is true
        )
    )

goto start