China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 15:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Batch file to install system patches — I can't continue writing it, can someone help me View 964 Replies 2
Original Poster Posted 2009-10-02 14:10 ·  中国 北京 联通
新手上路
Credits 5
Posts 3
Joined 2009-06-30 11:50
17-year member
UID 148440
Gender Male
Status Offline
This is the way I want it to look
Installed patch names as follows Installation progress 24/60
kB**** kb**** kb**** kb**** kb**** kb****
kB**** kb**** kb**** kb**** kb**** kb****
kB**** kb**** kb**** kb**** kb**** kb****
kB**** kb**** kb**** kb**** kb**** kb****


This is how my program currently looks when it runs
Installed patch names as follows Installation progress 24/60
kB****



Below is the incomplete code I wrote. I hope it can be completed
@echo off
title System patch package updated to ** year ** month ** day
MODE con: COLS=50 LINES=22
color 0a
:start0
echo ╭─────────────╮
echo ╭───┤ System Patch Installer ├───╮
echo │ ╰─────────────╯ │
echo │ 1.windows-XP-sp2 Chinese edition patch package │
echo │ 2.windows-XP-sp2 English edition patch package │
echo │ 3.Internet Explorer 6 patch package │
echo │ 4.Internet Explorer 7 patch package │
echo │ 5. Exit this program │
echo │ 6.Exit this program and restart the computer │
echo │ │
echo ╰─────────────────────╯
set /p list0=Please enter an option:
if "%list0%"=="1" goto list0_1
if "%list0%"=="2" goto list0_2
if "%list0%"=="3" goto list0_3
if "%list0%"=="4" goto list0_4
if "%list0%"=="5" goto list0_5
if "%list0%"=="6" goto list0_6
goto start0

:list0_1
MODE con: COLS=50 LINES=22
echo System patches will be installed shortly, press any key to continue
pause >nul

dir /b xp-sp2-chs\* >0.txt

set sum=0
set n=1

set tmep=replace_bak.tmp
setlocal enabledelayedexpansion

for /f "tokens=1* delims=:" %%i in ('findstr /i /n .* 0.txt') do (
set str=%%j
if not "!str!"=="" set "str=!str:.bat=!"
>>"%tmep%" echo.!str!
set /a sum=sum+1>nul
)
move "%tmep%" 0.txt

for /f "tokens=1* delims=:" %%m in (0.txt) do (
start /wait .\xp-sp2-chs\%%m.bat

cls
echo The following patches have been installed Progress: !n! /!sum!
echo %%m

set /a n=n+1
)
del 0.txt
echo Press any key to return to the main menu
pause >nul & goto start0


:list0_2






:list0_3





:list0_4




:list0_5
exit
:list0_6
::shutdown -r -t now
Floor 2 Posted 2009-10-05 10:58 ·  马来西亚
初级用户
Credits 31
Posts 19
Joined 2008-02-05 23:07
18-year member
UID 110255
Gender Male
Status Offline
I previously found 2 batch files for installing patches online.

Maybe you can use them for reference.


@echo off
title Unattended system patch installation!
color 1f
cls
MODE con: COLS=60 LINES=25
echo.
echo ###########################################
echo # #
echo # Net admin - Yamei D #
echo # #
echo # www.yamed.cn #
echo # #
echo ###########################################
echo.
echo Make sure the folder containing this file has the patches you need to install
echo Press any key to start installing!
pause >nul
cls
set tm1=%time:~0,2%
set tm2=%time:~3,2%
set tm3=%time:~6,2%
ECHO %date% %tm1% o'clock %tm2% minutes %tm3% seconds
echo Installing patches......
echo.
for %%i in (*.exe) do (
echo Installing %%i ......
%%i /passive /norestart /nobackup
)
set tm1=%time:~0,2%
set tm2=%time:~3,2%
set tm3=%time:~6,2%
ECHO %date% %tm1% o'clock %tm2% minutes %tm3% seconds
echo All patches have been installed!
echo ......
for /l %%m in (30,-1,1) do (
ping /n 2 127.1>nul
title %%m ...... The system will restart in 30 seconds!
)
shutdown -r -t 0



hihi~ 大家好,小弟初到贵处,请各位高手多多指教。。。:)
Floor 3 Posted 2009-10-05 10:59 ·  马来西亚
初级用户
Credits 31
Posts 19
Joined 2008-02-05 23:07
18-year member
UID 110255
Gender Male
Status Offline
Here's another, more advanced one.


@ECHO off
REM By zzzfinal
SET TITLE=Windows Patch Installation Script V0.070408
TITLE %TITLE%
SETLOCAL ENABLEDELAYEDEXPANSION
SET PATCHFLAG=KB
SET CAT=%PATCHFLAG%*.cat
SET PATCHLIST="%temp%\patcheslist.tmp"
SET INSTALLED=√ Installed
SET NOTINSTALLED=× Not installed
SET DELIMS=-----------------------------------------
SET PATCH_TOTAL=0
SET PATCH_NOTINSTALLED=0
SET FLAG_INSTALLED=1*
SET FLAG_NOTINSTALLED=0*

:main
TITLE Searching... -- %TITLE%
ECHO Searching the current directory "%cd%" and its subdirectories for patches...
ECHO If you want to install the uninstalled patches immediately after the search is complete, just press Enter.
ECHO.
REM Search for patches; if none are found then exit, otherwise continue.
CALL :pfind || (call :error 1& goto :eof)
ECHO.
:confirm
TITLE Please choose which patches to install -- %TITLE%
ECHO A total of %PATCH_TOTAL% patches were found above, of which %PATCH_NOTINSTALLED% are not installed. To install all of them, enter ALL. Otherwise just press Enter to install only the ones not yet installed.
SET confirm=
SET /p confirm=
IF /i "%confirm%" == "ALL" (SET confirm=
) ELSE IF not defined confirm (SET confirm=%FLAG_INSTALLED:~0,1%
) ELSE GOTO confirm
ECHO %DELIMS%
ECHO.
ECHO Installing now, please wait. The installer will not steal window focus, so you can do something else :)
ECHO.
CALL :setup %confirm%
del %PATCHLIST% 2>nul >nul
TITLE Installation finished -- %TITLE%
ECHO %DELIMS%
ECHO.
ECHO Installation is finished. For the patches to take effect, you may need to restart the computer manually.
ECHO Press any key to exit.
SET TITLE=
ENDLOCAL
PAUSE >nul
TITLE %ComSpec%
goto :eof

REM Install patches
:setup
if "%1" == "" (set patchsum=%PATCH_TOTAL%) ELSE set patchsum=%PATCH_NOTINSTALLED%
set patch_counter=0
FOR /f "eol=%1 usebackq tokens=2,*" %%i in (%PATCHLIST%) DO (
set /a patch_counter+=1
TITLE !patch_counter!/%patchsum%-%%i -- %TITLE%
set nobackup=nobackup
echo %%i | find /i "%PATCHFLAG%8" 2>nul >nul && set nobackup=n
%%j /quiet /passive /norestart /!nobackup! 2>nul >nul
ECHO !patch_counter!/%patchsum% %%i √)
goto :eof

REM Search for patches in the current directory; non-zero return value means failure.
:pfind
SET REG=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
SET listinreg="%temp%\listinreg.tmp"
reg query %reg%>%listinreg%
del %PATCHLIST% 2>nul >nul
REM The patch is a compressed package
FOR /r %%i in (*%PATCHFLAG%*.exe) DO CALL :pfind.sub "%%~ni" "%%~fi" "%%~sfi"
REM The patch is inside the directory after the compressed package is extracted
FOR /r %%i in (%cat%) DO IF exist %%~dpiupdate.exe FOR /f %%j in ("%%~dpiupdate.exe") DO CALL :pfind.sub "%%~ni" "%%~fj" "%%~sfj"
IF not exist %PATCHLIST% EXIT /b 1
sort %PATCHLIST% /o %PATCHLIST%
rem Get the number of patches
FOR /f "tokens=3 delims= " %%i in ('find /c /i "%FLAG_NOTINSTALLED%" %PATCHLIST%') DO SET PATCH_NOTINSTALLED=%%i
FOR /f "tokens=3 delims= " %%i in ('find /c /i "%FLAG_INSTALLED%" %PATCHLIST%') DO SET /a PATCH_TOTAL=%%i + %PATCH_NOTINSTALLED%
del %listinreg% 2>nul >nul
IF not defined patch_total EXIT /b 2
IF %patch_total% LSS 1 EXIT /b 3
EXIT /b 0
goto :eof
REM Check whether the patch is installed, then write it to standard output and to %PATCHLIST%
:pfind.sub
IF "%~3" == "" GOTO :eof
CALL :getkbnum %1
SET id=!errorlevel!
IF not "!id!" == "-1" (
find /i "!id!" %listinreg% 2>nul >nul && (
set status=%FLAG_INSTALLED%& set isinstalled=%INSTALLED%
)||(set status=%FLAG_NOTINSTALLED%& set isinstalled=%NOTINSTALLED%)
ECHO !status! %PATCHFLAG%!id! %2>>%PATCHLIST%
ECHO !isinstalled! %PATCHFLAG%!id! %3
)
goto :eof

REM Return the KB number in the given string; return -1 on failure.
:getkbnum
SETLOCAL ENABLEDELAYEDEXPANSION
SET str=%~1
IF not defined str EXIT /b -1
IF not defined PATCHFLAG SET PATCHFLAG=KB
echo %PATCHFLAG%>getsize.tmp
for %%i in (getsize.tmp) do SET /a offset=%%~zi-2
del getsize.tmp 2>nul >nul
SET start=0
REM If there is only %PATCHFLAG%, return -1
IF /i "%str%" == "%PATCHFLAG%" EXIT /b -1
REM Delete the characters before %PATCHFLAG%; if deletion fails then return -1
:getkbnum.findkb
IF "%~1" == "!str!" (IF "!str:~%start%,%offset%!" == "" (EXIT /b -1
) ELSE IF /i "!str:~%start%,%offset%!" == "%PATCHFLAG%" (SET str=!str:~%start%!
) ELSE (SET /a start+=1 & goto getkbnum.findkb))
REM If there is only %PATCHFLAG%, return -1
SET str=!str:~%offset%!
IF "%str%" == "" EXIT /b -1
SET start=0
REM Make sure it still returns -1 if the first character after %PATCHFLAG% is not a digit
IF "!str:~%start%,1!" GTR "9" EXIT /b -1
IF "!str:~%start%,1!" LSS "0" EXIT /b -1
REM Return the digits after %PATCHFLAG%
:getkbnum.findnum
IF "!str:~%start%,1!" GTR "9" EXIT /b !str:~0,%start%!
IF "!str:~%start%,1!" LSS "0" EXIT /b !str:~0,%start%!
SET /a start+=1
goto getkbnum.findnum
ENDLOCAL
EXIT /b -1

:error
TITLE ERROR -- %TITLE%
IF "%1" == "1" (ECHO No patches were found. The search rules used are: CAT:%cat%,PATCHFLAG:%PATCHFLAG%. The program has ended.)
SET TITLE=
PAUSE >nul
TITLE %ComSpec%
goto :eof


hihi~ 大家好,小弟初到贵处,请各位高手多多指教。。。:)
Forum Jump: