demo
@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
开机管理员权限 启动 LanmanServer 、 com.docker.service
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
sc.exe config LanmanServer start=auto
sc.exe start LanmanServer
sc.exe start com.docker.service