带进度条的自动运行系统补丁包程序的批处理
功能:自动判断当前系统,并逐个运行当前文件夹里面的系统补丁包程序。
@echo off
:: hnfeng 20120416
:: ◆自动运行文件夹里面所有系统补丁程序并显示总进度及正在安装的程序名◆
:: ================================
cd /d "%~dp0"&color 3E&mode con lines=15 &title 补丁包批处理安装程序〔hnfeng〕
ver | find "6.1" > NUL && (set XT=Windows7&set CX=Windows6.1-KB*.msu&set CS=/quiet /norestart&goto TOP)
ver | find "5.1" > NUL && (set XT=WindowsXP&set CX=WindowsXP-KB*.exe&set CS=/quiet /norestart /nobackup&goto TOP)
ver | find "5.0" > NUL && (set XT=Windows2000&set CX=Windows2000-KB*.exe&set CS=/quiet /norestart /nobackup&goto TOP)
ver | find "5.2" > NUL && (set XT=Windows2003&set CX=WindowsServer2003-KB*.exe&set CS=/quiet /norestart /nobackup&goto TOP)
ver | find "6.0" > NUL && (set XT=WindowsVista&set CX=Windows6.0-KB*.msu&set CS=/quiet /norestart&goto TOP)
:: ================================
:TOP
set title=%XT% 补丁包批处理安装程序〔hnfeng〕
title %title%
set work=0&set n=0&set mo=0&set number=0&set hotfix=
if not exist %CX% echo.&echo.&echo 没找到补丁程序,按任意键退出 ...&echo.&echo.&echo (该批处理应该在系统补丁程序所在文件夹里运行.)&pause>nul&exit
set k=▏&set kn=0
:Kong
if %kn% LSS 33 (set k=%k% &set /a kn=%kn%+1&goto Kong)
for /F %%s in ('dir /b /a-d %CX% ^| find /v /c ""') do set all=%%s
for /F %%i in ('dir /b /a-d /OD %CX%') do (set hotfix=%%i&call :show)
set hotfix=&call :show
goto end
:show
:check
if %number% GTR %mo% set num=%num%█&set /a mo=%mo%+1&set k=%k:~0,-1%&goto check
cls&echo.&echo.
if "%hotfix%"=="" (echo %title% ) else (echo 正在安装:%hotfix% ...)
echo 进度: %n% / %all%
echo.&echo 已经完成 %work% %%%
echo ┌──────────────────────────────────┐
echo │%num%%k%│&echo │%num%%k%│&echo │%num%%k%│
echo └──────────────────────────────────┘
echo.
if not "%hotfix%"=="" echo hnfeng.2012.4
if %work%==100 goto :EOF
::ping 127.1 -n 2 >nul
%hotfix% %CS%
set /a n=%n%+1
set /a work=(%n%)*100/(%all%)
set /a number=%work%/3
set /a number=%number%+1
goto :EOF
:end
echo 运行完成,请按任意键退出... (建议重新启动系统)
pause>nul&exit
因为上面的批处理需要找到与当前系统相对应的补丁程序后才运行,如果你手里暂时没有补丁程序,可以创建一些虚假的补丁程序:
对于Win7, 创建30个文件:
for /L %%i in (10,1,30) do cd.>Windows6.1-KB610%%i.msu
pause
对于XP, 创建30个文件:
for /L %%i in (10,1,30) do cd.>WindowsXP-KB510%%i.exe
pause
然后把批处理里面的
::ping 127.1 -n 2 >nul
%hotfix% %CS%
改为
ping 127.1 -n 2 >nul
::%hotfix% %CS%
运行就能看到进度条。
对于 Office 2003/2007/2010,只需把这几行删掉
ver | find "6.1" > NUL && (set XT=Windows7&set CX=Windows6.1-KB*.msu&set CS=/quiet /norestart&goto TOP)
ver | find "5.1" > NUL && (set XT=WindowsXP&set CX=WindowsXP-KB*.exe&set CS=/quiet /norestart /nobackup&goto TOP)
ver | find "5.0" > NUL && (set XT=Windows2000&set CX=Windows2000-KB*.exe&set CS=/quiet /norestart /nobackup&goto TOP)
ver | find "5.2" > NUL && (set XT=Windows2003&set CX=WindowsServer2003-KB*.exe&set CS=/quiet /norestart /nobackup&goto TOP)
ver | find "6.0" > NUL && (set XT=WindowsVista&set CX=Windows6.0-KB*.msu&set CS=/quiet /norestart&goto TOP)
然后在此处增加下面内容:
set XT=Office2007_2010
set CX=*.exe
set CS=/quiet /norestart
如果是 Office2003,就这样:
set XT=Office2003
set CX=*.exe
set CS=/q
因为Office 2003、2007、2010可以同时存在,所以根据不同情况处理吧。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。