- @echo off
- color 2f
- mode con: cols=36 lines=8
- ECHO 自动安装截止3月份补丁
- FOR %%i IN (office\*.exe) DO cls& ECHO 正在安装 %%i 补丁,请稍候 &start /wait %%i /q
- REM By Leo
- SET TITLE=Windows 补丁安装脚本 V0.070408
- TITLE %TITLE%
- SETLOCAL ENABLEDELAYEDEXPANSION
- SET PATCHFLAG=KB
- SET CAT=%PATCHFLAG%*.cat
- SET PATCHLIST="%temp%\patcheslist.tmp"
- SET INSTALLED=√ 已安装
- SET NOTINSTALLED=× 未安装
- SET DELIMS=-----------------------------------------
- SET PATCH_TOTAL=0
- SET PATCH_NOTINSTALLED=0
- SET FLAG_INSTALLED=1*
- SET FLAG_NOTINSTALLED=0*
-
- :main
- TITLE 正在搜索... -- %TITLE%
- ECHO 正在搜索当前目录"%cd%"及其子目录下的补丁...
- ECHO 如果想在搜索完成后立即安装未安装的补丁,请按回车。
- ECHO.
- REM 搜索补丁,没有搜索到则退出,否则继续。
- CALL :pfind || (call :error 1& goto :eof)
- ECHO.
- :confirm
- TITLE 请选择要安装的补丁 -- %TITLE%
- ECHO 搜索到如上%PATCH_TOTAL%个补丁,其中%PATCH_NOTINSTALLED%个未安装。安装全部请输入ALL,否则请直接按回车安装尚未安装的补丁。
- 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 正在安装,请稍候。安装程序不会抢占窗口焦点,所以你可以干点别的:)
- ECHO.
- CALL :setup %confirm%
- del %PATCHLIST% 2>nul >nul
- TITLE 安装已结束 -- %TITLE%
- ECHO %DELIMS%
- ECHO.
- ECHO 安装已结束。要使补丁生效,你可能需要手动重新启动计算机。
- ECHO 按任意键退出。
- SET TITLE=
- ENDLOCAL
- PAUSE >nul
- TITLE %ComSpec%
- goto :eof
-
- REM 安装补丁
- :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 搜索当前目录下的补丁,返回非零值为失败。
- :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 补丁是一个压缩包
- FOR /r %%i in (*%PATCHFLAG%*.exe) DO CALL :pfind.sub "%%~ni" "%%~fi" "%%~sfi"
- REM 补丁在压缩包展开后的目录内
- 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 得到补丁个数
- 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 看看补丁安装了没,然后写到标准输出和%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 返回给定字串中的KB号,返回-1表示失败。
- :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 仅有%PATCHFLAG%则返回-1
- IF /i "%str%" == "%PATCHFLAG%" EXIT /b -1
- REM 删除%PATCHFLAG%前的字符,删除失败则返回-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 仅有%PATCHFLAG%则返回-1
- SET str=!str:~%offset%!
- IF "%str%" == "" EXIT /b -1
- SET start=0
- REM 保证%PATCHFLAG%后的第一个字符不是数字时,仍能返回-1
- IF "!str:~%start%,1!" GTR "9" EXIT /b -1
- IF "!str:~%start%,1!" LSS "0" EXIT /b -1
- REM 返回%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 没有找到补丁。使用的搜索规则是:CAT:%cat%,PATCHFLAG:%PATCHFLAG%。程序已结束。)
- SET TITLE=
-
- PAUSE >nul
- TITLE %ComSpec%
- goto :eof
复制代码
主要是能改成自动判断系统和OFFICE的补丁,有没有安装,如没有安装分别用参数自动安装,请高手们支招,谢谢
[ 本帖最后由 lzl88123 于 2011-3-17 10:12 编辑 ] |