Bat ·

一键保存 Windows 系统服务 bat

@echo off
echo.
echo   2015年10月1日  Email:service@fooher.com
echo 
echo    个人博客: http://www.fooher.com by 运维天涯
echo 
rem  get current date and time
for /f "tokens=1,2,3 delims=-/. " %%j in ('Date /T') do set FILENAME=srv_%%j_%%k_%%l
for /f "tokens=1,2 delims=: " %%j in ('TIME /T') do set FILENAME=%FILENAME%_%%j_%%k.bat

rem get all service name
sc query type= service state= all| findstr /r /C:"SERVICE_NAME:" >fooher_com.txt
echo Save Service Start State In %FILENAME%
rem save service start state into batch file 
rem

echo @echo Restore The Service Start State Saved At %TIME% %DATE% >"%FILENAME%" 
echo @pause >>"%FILENAME%"

for /f "tokens=2 delims=:" %%j in (fooher_com.txt) do @( sc qc %%j |findstr  START_TYPE >tmpfooher.txt &&  for /f "tokens=4 delims=:_ " %%s in ( tmpfooher.txt) do @echo sc config  %%j start= %%s >>"%FILENAME%")
echo @pause >>"%FILENAME%"

del fooher_com.txt
del tmpfooher.txt

 

评论已关闭