赞
踩
主脚本,整体实现逻辑都在这
-
- @ECHO OFF
- REM 自动判断权限问题,主动获取管理员权限
-
- >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
-
- if '%errorlevel%' NEQ '0' (
- 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"
-
- :begin
-
- chcp 65001
-
- echo 开始安装补丁,期间会重启服务器,请耐心等待...
-
- @REM 安装KB2919442补丁
- wusa.exe %~dp0Windows8.1-KB2919442-x64.msu /quiet /norestart
- echo KB2919442安装完成
-
- @REM ---------------修改任务信息------------------
- @REM 获取脚本路径
-
- set dir_tmp=%~dp0
- set dir=%dir_tmp:\=\\\\%
-
-
- @REM 修改系统任务文件
- sed -i '79d' .\test.xml
- sed -i "78a\ <Command>%dir%install_left.bat</Command>" .\test.xml
- sed -i '81d' .\test.xml
- sed -i "80a\ <WorkingDirectory>%dir%</WorkingDirectory>" .\test.xml
- @REM ---------------修改任务信息------------------
-
- @REM 重新导入(覆盖旧任务)
- schtasks.exe /create /tn test /xml test.xml /f
-
- @REM clearcompressionflag
- clearcompressionflag.exe
- @REM KB2919355补丁安装,安装完成必须重启,安装时间会有点长,请耐心等待
- wusa.exe %~dp0Windows8.1-KB2919355-x64.msu /quiet /norestart
- echo KB2919355安装完成
- @REM @REM 设置自启动任务,系统重启之后自动运行install_left.bat
- @REM schtasks /create /tn test /f /z /tr "%~dp0install.vbs" /sc onstart /ru system
-
-
- echo 准备重启服务器
- @REM 设置超时时间,让客户看到提示
-
- REM 重启服务器
- shutdown -r -f -t 5
- pause
-
安装不需要重启的补丁,放到最后去安装
主脚本会添加一个计划任务,服务器开机之后会启动脚本去安装
该脚本执行完成之后会删除计划任务
-
- @ECHO OFF
- REM 自动判断权限问题,主动获取管理员权限
-
- >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
-
- if '%errorlevel%' NEQ '0' (
- 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"
-
- :begin
-
- @REM 安装重启之后剩下的不定
- wusa.exe %~dp0Windows8.1-KB2932046-x64.msu /quiet /norestart
- wusa.exe %~dp0Windows8.1-KB2934018-x64.msu /quiet /norestart
- wusa.exe %~dp0Windows8.1-KB2937592-x64.msu /quiet /norestart
- wusa.exe %~dp0Windows8.1-KB2938439-x64.msu /quiet /norestart
- wusa.exe %~dp0Windows8.1-KB2959977-x64.msu /quiet /norestart
-
- @REM 删除任务
- schtasks /delete /tn "test" /f
-
计划任务相关配置文件
- <?xml version="1.0" encoding="UTF-16"?>
-
- <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
-
- <RegistrationInfo>
-
- <Date>2023-10-15T13:12:22</Date>
-
- <Author>Administrator</Author>
-
- </RegistrationInfo>
-
- <Triggers>
-
- <BootTrigger>
-
- <StartBoundary>2023-10-15T13:12:00</StartBoundary>
-
- <Enabled>true</Enabled>
-
- </BootTrigger>
-
- </Triggers>
-
- <Principals>
-
- <Principal id="Author">
-
- <RunLevel>LeastPrivilege</RunLevel>
-
- <UserId>S-1-5-18</UserId>
-
- </Principal>
-
- </Principals>
-
- <Settings>
-
- <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
-
- <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
-
- <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
-
- <AllowHardTerminate>true</AllowHardTerminate>
-
- <StartWhenAvailable>false</StartWhenAvailable>
-
- <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
-
- <IdleSettings>
-
- <StopOnIdleEnd>true</StopOnIdleEnd>
-
- <RestartOnIdle>false</RestartOnIdle>
-
- </IdleSettings>
-
- <AllowStartOnDemand>true</AllowStartOnDemand>
-
- <Enabled>true</Enabled>
-
- <Hidden>false</Hidden>
-
- <RunOnlyIfIdle>false</RunOnlyIfIdle>
-
- <WakeToRun>false</WakeToRun>
-
- <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
-
- <Priority>7</Priority>
-
- </Settings>
-
- <Actions Context="Author">
-
- <Exec>
-
- <Command>E:\git_code\windows_server_2012_patch\install_left.bat</Command>
-
- <WorkingDirectory>E:\git_code\windows_server_2012_patch\</WorkingDirectory>
-
- </Exec>
-
- </Actions>
-
- </Task>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。