当前位置:   article > 正文

bat一键给windows server 2012 打补丁_server2012 补丁

server2012 补丁

流程图

脚本

install.bat

主脚本,整体实现逻辑都在这

  1. @ECHO OFF
  2. REM 自动判断权限问题,主动获取管理员权限
  3. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  4. if '%errorlevel%' NEQ '0' (
  5. goto UACPrompt
  6. ) else ( goto gotAdmin )
  7. :UACPrompt
  8. echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  9. echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
  10. "%temp%\getadmin.vbs"
  11. exit /B
  12. :gotAdmin
  13. if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
  14. pushd "%CD%"
  15. CD /D "%~dp0"
  16. :begin
  17. chcp 65001
  18. echo 开始安装补丁,期间会重启服务器,请耐心等待...
  19. @REM 安装KB2919442补丁
  20. wusa.exe %~dp0Windows8.1-KB2919442-x64.msu /quiet /norestart
  21. echo KB2919442安装完成
  22. @REM ---------------修改任务信息------------------
  23. @REM 获取脚本路径
  24. set dir_tmp=%~dp0
  25. set dir=%dir_tmp:\=\\\\%
  26. @REM 修改系统任务文件
  27. sed -i '79d' .\test.xml
  28. sed -i "78a\ <Command>%dir%install_left.bat</Command>" .\test.xml
  29. sed -i '81d' .\test.xml
  30. sed -i "80a\ <WorkingDirectory>%dir%</WorkingDirectory>" .\test.xml
  31. @REM ---------------修改任务信息------------------
  32. @REM 重新导入(覆盖旧任务)
  33. schtasks.exe /create /tn test /xml test.xml /f
  34. @REM clearcompressionflag
  35. clearcompressionflag.exe
  36. @REM KB2919355补丁安装,安装完成必须重启,安装时间会有点长,请耐心等待
  37. wusa.exe %~dp0Windows8.1-KB2919355-x64.msu /quiet /norestart
  38. echo KB2919355安装完成
  39. @REM @REM 设置自启动任务,系统重启之后自动运行install_left.bat
  40. @REM schtasks /create /tn test /f /z /tr "%~dp0install.vbs" /sc onstart /ru system
  41. echo 准备重启服务器
  42. @REM 设置超时时间,让客户看到提示
  43. REM 重启服务器
  44. shutdown -r -f -t 5
  45. pause

install_left.bat

安装不需要重启的补丁,放到最后去安装

主脚本会添加一个计划任务,服务器开机之后会启动脚本去安装

脚本执行完成之后会删除计划任务

  1. @ECHO OFF
  2. REM 自动判断权限问题,主动获取管理员权限
  3. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  4. if '%errorlevel%' NEQ '0' (
  5. goto UACPrompt
  6. ) else ( goto gotAdmin )
  7. :UACPrompt
  8. echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  9. echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
  10. "%temp%\getadmin.vbs"
  11. exit /B
  12. :gotAdmin
  13. if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
  14. pushd "%CD%"
  15. CD /D "%~dp0"
  16. :begin
  17. @REM 安装重启之后剩下的不定
  18. wusa.exe %~dp0Windows8.1-KB2932046-x64.msu /quiet /norestart
  19. wusa.exe %~dp0Windows8.1-KB2934018-x64.msu /quiet /norestart
  20. wusa.exe %~dp0Windows8.1-KB2937592-x64.msu /quiet /norestart
  21. wusa.exe %~dp0Windows8.1-KB2938439-x64.msu /quiet /norestart
  22. wusa.exe %~dp0Windows8.1-KB2959977-x64.msu /quiet /norestart
  23. @REM 删除任务
  24. schtasks /delete /tn "test" /f

 test.xml

计划任务相关配置文件

  1. <?xml version="1.0" encoding="UTF-16"?>
  2. <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  3. <RegistrationInfo>
  4. <Date>2023-10-15T13:12:22</Date>
  5. <Author>Administrator</Author>
  6. </RegistrationInfo>
  7. <Triggers>
  8. <BootTrigger>
  9. <StartBoundary>2023-10-15T13:12:00</StartBoundary>
  10. <Enabled>true</Enabled>
  11. </BootTrigger>
  12. </Triggers>
  13. <Principals>
  14. <Principal id="Author">
  15. <RunLevel>LeastPrivilege</RunLevel>
  16. <UserId>S-1-5-18</UserId>
  17. </Principal>
  18. </Principals>
  19. <Settings>
  20. <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
  21. <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
  22. <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
  23. <AllowHardTerminate>true</AllowHardTerminate>
  24. <StartWhenAvailable>false</StartWhenAvailable>
  25. <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
  26. <IdleSettings>
  27. <StopOnIdleEnd>true</StopOnIdleEnd>
  28. <RestartOnIdle>false</RestartOnIdle>
  29. </IdleSettings>
  30. <AllowStartOnDemand>true</AllowStartOnDemand>
  31. <Enabled>true</Enabled>
  32. <Hidden>false</Hidden>
  33. <RunOnlyIfIdle>false</RunOnlyIfIdle>
  34. <WakeToRun>false</WakeToRun>
  35. <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
  36. <Priority>7</Priority>
  37. </Settings>
  38. <Actions Context="Author">
  39. <Exec>
  40. <Command>E:\git_code\windows_server_2012_patch\install_left.bat</Command>
  41. <WorkingDirectory>E:\git_code\windows_server_2012_patch\</WorkingDirectory>
  42. </Exec>
  43. </Actions>
  44. </Task>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/1012417
推荐阅读
相关标签
  

闽ICP备14008679号