|
我自己专为WIN系统写的批处理,自动侦测WIN系统版本,并根据系统已有的补丁来判断还有多少补丁没有安装,最终自动安装系统没有的补丁程序。另外将此批处理与补丁放在同一目录内就可运行了。 横线下边的就是自动安装系统补丁批处理了。
=================================================================================================================================================
@echo off
title 系统补丁批量自动安装
color 1f
cls
PUSHD %~dp0
del /q /f *.txt
rem //判断WIN7、WIN8、WIN10系统并获取最高权限
ver|find /i "10.0." > NUL && goto UACwin10
ver|find /i "6.3." > NUL && goto UACwin8
ver|find /i "6.2." > NUL && goto UACwin8
ver|find /i "6.1." > NUL && goto UACwin7
ver|find /i "6.0." > NUL && goto UACwin7
ver|find /i "5.00"> NUL && goto fixpatch
ver|find /i "5.1"> NUL && goto fixpatch
ver|find /i "5.2"> NUL && goto fixpatch
IF EXIST %SystemRoot%\System32\PECMD.INI goto ErrSystem
:ErrSystem
cls
Echo.
Echo.
Echo 注意:经测试,本软件只适用于WINXP及其以上的Windows操作系统。
Echo 很遗憾,你的系统不符合本程序的要求。按回车键退出安装程序!!!
Pause >nul
Exit
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:fixpatch
IF /i not "%OS%."=="Windows_NT." goto ErrSystem
::判断系统版本并设置TheOS
ver|find /i "10.">nul &&SET Winver=nt6&& SET TheOS=Win10
ver|find /i "6.3">nul &&SET Winver=nt6&& SET TheOS=Win8.1
ver|find /i "6.2">nul &&SET Winver=nt6&& SET TheOS=Win8
ver|find /i "6.1">nul &&SET Winver=nt6&& SET TheOS=Win7
ver|find /i "6.0">nul &&SET Winver=nt6&& SET TheOS=Vista
ver|find /i "5.0">nul &&SET Winver=nt5&& SET TheOS=2000
ver|find /i "5.1">nul &&SET Winver=nt5&& SET TheOS=XP
ver|find /i "5.2">nul &&SET Winver=nt5&& SET TheOS=2003
cls
SET TP=%~dp0
SET TP=%TP:~0,-1%
cd /d %TP%
Echo.
@Echo **************************************************
@Echo ║ [1] 运行全自动安装补丁(全部补丁都安装) ║
@Echo ║ ║
@Echo ║ [2] 运行全自动安装补丁(系统已有的省略安装) ║
@Echo ║ ║
@Echo ║ [3] 删除全部补丁 ║
@Echo ║ ║
@Echo ║ [4] 查看目录内补丁 ║
@Echo ║ ║
@Echo ║ [5] 退出本程序 ║
@Echo **************************************************
Echo.
Echo 您现在使用的是 %TheOS% 操作系统,请确保您拥有管理员权限
IF "%Winver%"=="nt6" Echo 并关闭了UAC和360等保护软件,否则安装可能失败!
Echo.
SET Choice=
SET /P Choice= 请选择要进行的操作 (1/2/3/4/5=退出) ,然后按回车:
Echo.
IF "%Choice%"=="" Goto fixpatch
IF Not "%Choice%"=="" SET Choice=%Choice:~0,1%
IF /I "%Choice%"=="1" Goto Start0
IF /I "%Choice%"=="2" Goto Start1
IF /I "%Choice%"=="3" Goto Del
IF /I "%Choice%"=="4" Goto Exp
IF /I "%Choice%"=="5" Goto Exit
rem //运行全自动安装补丁(全部补丁都安装)
:Start0
echo 请将此批处理与补丁放在同一目录内运行才能自动安装系统补丁
echo.
ver|find /i "5.00"> NUL && goto win_xp
ver|find /i "5.1"> NUL && goto win_xp
ver|find /i "5.2"> NUL && goto win_xp
rem //目录内补丁具体内容
dir /a /b *.msu > hotfix.txt
rem //显示目录内补丁总数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" hotfix.txt')do set/a patch1=%%a+0
echo.
echo.
@echo 总共要自动安装的系统补丁数:%patch1%
echo.
rem //生成安装批处理程序
echo.@echo off >install.cmd
echo.title win系统补丁自动安装 >>install.cmd
echo echo.总共要安装 %patch1% 个补丁 >>install.cmd
echo echo. >>install.cmd
for /l %%i in (1,1,%patch1%) do echo echo.Windows有%patch1%个补丁要安装,正在安装第%%i个补丁,请稍等......>>hotfixA.txt
echo echo. >>install.cmd
ver|find /i "6.2." > NUL && goto W8
ver|find /i "6.3." > NUL && goto W8
for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait wusa %%i /quiet /norestart>>hotfixB.txt
GOTO W7
:W8
for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait %%i /quiet /norestart>>hotfixB.txt
:W7
rem //合并成一个文件并生成批处理命令
setlocal enabledelayedexpansion
echo.
set "间隔行数=1"
echo.
for /f "delims=" %%a in (hotfixB.txt) do (
set /a LineA+=1
set "_!LineA!=%%a"
)
(for /f "delims=" %%a in (hotfixA.txt) do (
echo,%%a
set /a "m=(LineB+=1)%%间隔行数, x+=^!m, y=(x-1)%%LineA+1"
if "!m!" == "0" for %%b in (!y!) do echo,!_%%b!
))>>install.cmd
echo.
echo echo.系统安装完成,将在40秒后关闭电脑。 >>install.cmd
echo.
echo Shutdown.exe -s -t 40 >>install.cmd
echo exit>>install.cmd
rem //删除hotfixA.txt
if exist hotfixA.txt del /q /f hotfixA.txt
rem //删除hotfixB.txt
if exist hotfixB.txt del /q /f hotfixB.txt
rem //删除
del /q /f hotfix*.txt
rem //准备运行install.cmd
if exist install.cmd start /wait install.cmd
rem //删除install.cmd
if exist install.cmd del /q /f install.cmd
echo.
echo 39秒后自动关闭电脑!
Shutdown.exe -s -t 39
exit
rem //运行全自动安装补丁(系统已有的省略安装)
:Start1
echo.
echo 请将此批处理与补丁放在同一目录内运行才能自动安装系统补丁...
echo.
ver|find /i "5.00"> NUL && goto win_xp1
ver|find /i "5.1"> NUL && goto win_xp1
ver|find /i "5.2"> NUL && goto win_xp1
color 0A
cls
rem //已经安装在系统上的补丁
for /f "tokens=2" %%a in ('systeminfo^|findstr /i "KB"') do (
echo %%a>>info.txt
)
rem //目录内所有补丁中还没安装上系统的补丁patch
rem //目录内补丁具体内容
dir /a /b *.msu > hotfix.txt
rem //显示目录内补丁总数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" hotfix.txt')do set/a patch1=%%a+0
copy /y hotfix.txt patch.txt >nul
for /f "delims=" %%a in (info.txt) do (
type patch.txt|find /i "%%a">nul&&(type patch.txt|find /v /i "%%a")>temp.txt
move /y temp.txt patch.txt >nul 2>nul
)
echo.
echo 目录内补丁总共有%patch1%个
Echo.
rem //显示目录内所有补丁中还没安装上系统的补丁的个数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" patch.txt')do set/a patch2=%%a+0
echo 目录内所有补丁中还没安装上系统的补丁有%patch2%个
if %patch2%==0 goto qqq
rem //生成安装批处理程序
echo.@echo off >install.cmd
echo.title win系统补丁自动安装 >>install.cmd
echo echo. >>install.cmd
echo echo.目录内总共有 %patch1% 个补丁,其中有 %patch2% 个补丁未被安装 >>install.cmd
echo echo. >>install.cmd
for /l %%i in (1,1,%patch2%) do echo echo.Windows有%patch2%个补丁将要安装,正在安装第%%i个补丁,请稍等......>>hotfixA.txt
ver|find /i "6.2." > NUL && goto W81
ver|find /i "6.3." > NUL && goto W81
for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait wusa %%i /quiet /norestart>>hotfixB.txt
GOTO W71
rem //win8和win8.1补丁安装方法
:W81
for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait %%i /quiet /norestart>>hotfixB.txt
:W71
rem //合并成一个文件并生成批处理命令
setlocal enabledelayedexpansion
echo.
set "间隔行数=1"
echo.
for /f "delims=" %%a in (hotfixB.txt) do (
set /a LineA+=1
set "_!LineA!=%%a"
)
(for /f "delims=" %%a in (hotfixA.txt) do (
echo,%%a
set /a "m=(LineB+=1)%%间隔行数, x+=^!m, y=(x-1)%%LineA+1"
if "!m!" == "0" for %%b in (!y!) do echo,!_%%b!
))>>install.cmd
echo echo. >>install.cmd
echo echo.系统安装完成,将在40秒后关闭电脑。 >>install.cmd
echo.
echo Shutdown.exe -s -t 40 >>install.cmd
echo exit>>install.cmd
Echo.
Echo.
Pause
if exist info.txt del /q /f info*.txt
if exist hotfix.txt del /q /f hotfix*.txt
if exist patch.txt del /q /f *.txt
rem //准备运行install.cmd
if exist install.cmd start /wait install.cmd
rem //删除install.cmd
if exist install.cmd del /q /f install.cmd
exit
:qqq
echo.
echo.你的系统已经装过了目录内的补丁了!!!按任意键退出!
pause
exit
:win_xp
rem //winxp补丁(全部补丁都安装)
cls
echo.
echo.
rem //目录内补丁具体内容
dir /a /b *.exe > hotfix.txt
rem //显示目录内补丁总数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" hotfix.txt')do set/a patch1=%%a+0
echo.
echo.
@echo 总共要自动安装的系统补丁数:%patch1%
echo.
rem //生成安装批处理程序
echo.@echo off >install.cmd
echo.title win系统补丁自动安装 >>install.cmd
echo echo.总共要安装 %patch1% 个补丁 >>install.cmd
echo echo. >>install.cmd
for /l %%i in (1,1,%patch1%) do echo echo.Windows有%patch1%个补丁要安装,正在安装第%%i个补丁,请稍等......>>hotfixA.txt
echo echo. >>install.cmd
for /f "tokens=1" %%i in (hotfix.txt) do echo.start /wait %%i /passive /norestart /nobackup>>hotfixB.txt
rem //合并成一个文件并生成批处理命令
setlocal enabledelayedexpansion
echo.
set "间隔行数=1"
echo.
for /f "delims=" %%a in (hotfixB.txt) do (
set /a LineA+=1
set "_!LineA!=%%a"
)
(for /f "delims=" %%a in (hotfixA.txt) do (
echo,%%a
set /a "m=(LineB+=1)%%间隔行数, x+=^!m, y=(x-1)%%LineA+1"
if "!m!" == "0" for %%b in (!y!) do echo,!_%%b!
))>>install.cmd
echo exit>>install.cmd
rem //删除hotfixA.txt
if exist hotfixA.txt del /q /f hotfixA.txt
rem //删除hotfixB.txt
if exist hotfixB.txt del /q /f hotfixB.txt
rem //删除
del /q /f hotfix*.txt
rem //准备运行install.cmd
if exist install.cmd start /wait install.cmd
rem //删除install.cmd
if exist install.cmd del /q /f install.cmd
echo.
echo 39秒后自动关闭电脑!
Shutdown.exe -s -t 39
exit
:win_xp1
rem //winxp补丁(系统未安装的补丁才装)
echo.
echo 请将此批处理与Windows补丁放在同一目录内运行才能自动安装系统补丁
echo.
rem ========目录内所有补丁中还没安装上系统的补丁==================
rem //目录内补丁具体内容
dir /a /b *.exe > hotfix.txt
rem //显示目录内补丁总数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" hotfix.txt')do set/a patch1=%%a+0
ver|find /i "5.00"> NUL && goto win_2k1
ver|find /i "5.1"> NUL && goto win_2k1
rem //已安装在系统上的补丁情况
for /f "tokens=2" %%a in ('systeminfo^|findstr /i "KB"') do (
echo %%a>>info.txt
)
copy /y hotfix.txt patch.txt >nul
for /f "delims=" %%a in (info.txt) do (
type patch.txt|find /i "%%a">nul&&(type patch.txt|find /v /i "%%a")>temp.txt
move /y temp.txt patch.txt >nul 2>nul
)
goto xp2k
:win_2k1
echo.
echo 正在检测已经安装的补丁
rem //从文件中取出一个补丁的名字,截取中间的补丁标号(如KB873339),到注册表查询这个是否已经安装了,没有就将其存放到patch.txt文件里
for /f "delims=- tokens=2" %%i in ('dir *-kb*.exe /b /on') do REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix\%%i" >nul || dir /b *%%i*.exe >>patch.txt && cls && echo 正在检测已经安装的补丁
goto xp2k
exit
:xp2k
echo.
echo 目录内补丁总共有%patch1%个
Echo.
rem //显示目录内所有补丁中还没安装上系统的补丁的个数
for /f "tokens=2 delims=:" %%a in ('find /c /v "" patch.txt')do set/a patch2=%%a+0
echo.
echo 目录内所有补丁中还没安装上系统的补丁有%patch2%个
echo.
if %patch2%==0 goto qqq
rem //生成安装批处理程序
echo.@echo off >install.cmd
echo.title win系统补丁自动安装 >>install.cmd
echo.
echo echo.目录内总共有 %patch1% 个补丁,其中有 %patch2% 个补丁未被安装 >>install.cmd
echo echo. >>install.cmd
for /l %%i in (1,1,%patch2%) do echo echo.Windows有%patch2%个补丁将要安装,正在安装第%%i个补丁,请稍等......>>hotfixA.txt
for /f "tokens=1" %%i in (patch.txt) do echo.start /wait %%i /passive /norestart /nobackup>>hotfixB.txt
rem //合并成一个文件并生成批处理命令
setlocal enabledelayedexpansion
echo.
set "间隔行数=1"
echo.
for /f "delims=" %%a in (hotfixB.txt) do (
set /a LineA+=1
set "_!LineA!=%%a"
)
(for /f "delims=" %%a in (hotfixA.txt) do (
echo,%%a
set /a "m=(LineB+=1)%%间隔行数, x+=^!m, y=(x-1)%%LineA+1"
if "!m!" == "0" for %%b in (!y!) do echo,!_%%b!
))>>install.cmd
echo.
echo echo.系统安装完成,将在40秒后关闭电脑。 >>install.cmd
echo.
echo Shutdown.exe -s -t 40 >>install.cmd
echo exit>>install.cmd
pause
Echo.
rem //准备运行install.cmd
if exist install.cmd start /wait install.cmd
rem //删除install.cmd
if exist install.cmd del /q /f install.cmd
Echo.
if exist info.txt del /q /f info*.txt
if exist hotfix.txt del /q /f hotfix*.txt
if exist patch.txt del /q /f *.txt
exit
:Exp
explorer %TP%
goto fixpatch
exit
:Del
echo 按任意键将删除目录内全部补丁文件,并退出程序!!!
pause
del /q /f *.exe
del /q /f *.msu
exit
:UACwin7
CLS
ECHO.
ECHO ================================
ECHO WIN7获取批处理文件管理员权限
ECHO ================================
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges(请求管理员权限)...
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"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 以下为需要运行的批处理文件代码 ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem 本行以下可修改为你需要的批处理命令
rem //去除WIN7-UAC小盾牌(重启电脑生效)
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /f /v EnableLUA /t REG_DWORD /d 0
taskkill /f /im explorer.exe
attrib -s -r -h "%userprofile%\AppData\Local\iconcache.db"
del "%userprofile%\AppData\Local\iconcache.db" /f /q
start explorer
goto fixpatch
exit
:UACwin8
CLS
ECHO.
ECHO ================================
ECHO WIN8获取批处理文件管理员权限
ECHO ================================
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges(请求管理员权限)...
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"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 以下为需要运行的批处理文件代码 ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem 本行以下可修改为你需要的批处理命令
rem //去除WIN8.1-UAC小盾牌
taskkill /f /im explorer.exe
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 77 /d "%systemroot%\system32\imageres.dll,197" /t reg_sz /f
del "%userprofile%\AppData\Local\iconcache.db" /f /q
taskkill /f /im explorer.exe
start %systemroot%\explorer
goto fixpatch
exit
:UACwin10
CLS
ECHO.
ECHO ================================
ECHO WIN10获取批处理文件管理员权限
ECHO ================================
:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO.
ECHO ********************************
ECHO 请求 UAC 权限批准……
ECHO ********************************
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit /B
:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 以下为需要运行的批处理文件代码 ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
rem 本行以下可修改为你需要的批处理命令
REM //关闭WIN10用户账户控制(UAC)
rem reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "EnableLUA" /d 0 /t REG_DWORD /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "ConsentPromptBehaviorAdmin" /d 0 /t REG_DWORD /f
goto fixpatch
exit |
|