@ECHO off REM By Leo SETTITLE=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= ) ELSEIFnotdefined confirm (SET confirm=%FLAG_INSTALLED:~0,1% ) ELSEGOTO confirm ECHO%DELIMS% ECHO. ECHO 正在安装,请稍候。安装程序不会抢占窗口焦点,所以你可以干点别的:) ECHO. CALL :setup %confirm% del%PATCHLIST%2>nul >nul TITLE 安装已结束 -- %TITLE% ECHO%DELIMS% ECHO. ECHO 安装已结束。要使补丁生效,你可能需要手动重新启动计算机。 ECHO 按任意键退出。 SETTITLE= ENDLOCAL PAUSE >nul TITLE%ComSpec% goto :eof REM 安装补丁 :setup if "%1" == "" (set patchsum=%PATCH_TOTAL%) ELSEset patchsum=%PATCH_NOTINSTALLED% set patch_counter=0 FOR /f "eol=%1 usebackq tokens=2,*" %%iin (%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 %%iin (*%PATCHFLAG%*.exe) DOCALL :pfind.sub "%%~ni" "%%~fi" "%%~sfi" REM 补丁在压缩包展开后的目录内 FOR /r %%iin (%cat%) DOIFexist%%~dpiupdate.exe FOR /f %%jin ("%%~dpiupdate.exe") DOCALL :pfind.sub "%%~ni" "%%~fj" "%%~sfj" IFnotexist%PATCHLIST%EXIT /b 1 sort %PATCHLIST% /o %PATCHLIST% rem 得到补丁个数 FOR /f "tokens=3 delims= " %%iin ('find /c /i "%FLAG_NOTINSTALLED%" %PATCHLIST%') DOSET PATCH_NOTINSTALLED=%%i FOR /f "tokens=3 delims= " %%iin ('find /c /i "%FLAG_INSTALLED%" %PATCHLIST%') DOSET /a PATCH_TOTAL=%%i + %PATCH_NOTINSTALLED% del%listinreg%2>nul >nul IFnotdefined patch_total EXIT /b 2 IF%patch_total%LSS1EXIT /b 3 EXIT /b 0 goto :eof REM 看看补丁安装了没,然后写到标准输出和%PATCHLIST%内 :pfind.sub IF "%~3" == "" GOTO :eof CALL :getkbnum %1 SET id=!errorlevel! IFnot "!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 IFnotdefined str EXIT /b -1 IFnotdefined PATCHFLAG SET PATCHFLAG=KB echo%PATCHFLAG%>getsize.tmp for%%iin (getsize.tmp) doSET /a offset=%%~zi-2 del getsize.tmp 2>nul >nul SETstart=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 ) ELSEIF /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 SETstart=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%。程序已结束。) SETTITLE= PAUSE >nul TITLE%ComSpec% goto :eof
for /f "delims=" %%N in ('dir /A:D /B') ^ do ( xcopy createQuxian.cmd %%N /y ) pause
示例.利用批处理文件进行更改系统网络IP与网关。
1 2 3 4 5 6 7 8 9 10
@echo off set /p add=请输入IP地址最后一位(1~254): set address=10.10.102.%add% :: rem 以太网IP 与 网关设置 netsh interface ip set address name="以太网" source=static addr=%address% mask=255.255.255.0 gateway=10.10.102.1 gwmetric=1 :: rem 网络DNS域名解析服务器地址设置 netsh interface ip set dnsservers name="以太网" source=static address=192.168.10.254 register=primary :: 刷新DNS解析 ipconfig /flushdns ipconfig
方式1.请访问本博主的B站【WeiyiGeek】首页关注UP主, 将自动随机获取解锁验证码。
Method 2.Please visit 【My Twitter】. There is an article verification code in the homepage.
方式3.扫一扫下方二维码,关注本站官方公众号
回复:验证码
将获取解锁(有效期7天)本站所有技术文章哟!