📜 ⬆️ ⬇️

Check whether the service pack is present on the system before installation

Installing service packs for Windows can occur either automatically by Windows Update or manually through the Windows Update Stand-alone Installer (WUSA) - Standalone update installer from msu files. In addition to WUSA, you can also upgrade the OS using Deployment Image Servicing and Management (DISM) - Deployment Image Servicing and Management System. Using DISM, you can install updates on not only from msu-files, but also from cab-files. To get the update package cab file, you need to download the required msu file from the Microsoft website and unpack it with the / extract key. It is noticed that the installation of service packs in the form of cab files using DISM is faster than from msu files using WUSA. I choose DISM to work with Windows updates, so further description is provided for it.

Many system administrators collect their “collections” of service packs by running their installation in a specific sequence from a batch file. But sometimes, servicing unfamiliar computers, it is not known exactly which updates are installed and which ones are not. If you start the installation of all updates from a long list, then if there are some updates in the OS image, the DISM system will still install them “on top”. In order to avoid wasting time in my script, a “function” is used that checks the installed service pack for its presence in the OS. In the script code, for example, installation of updates KB3177467 (Servicing stack update) and KB3125574 (Convenience rollup update) is performed . The OS also automatically determines the bitness of the OS, but this does not concern the topic of the question.

Script:

@echo off set arch=x64 if "%PROCESSOR_ARCHITECTURE%" == "x86" if not defined PROCESSOR_ARCHITEW6432 set arch=x86 echo The most important updates after SP1 (Convenience rollup) %arch% echo ------------------------------------------------------------------------------- echo Get packages list. Please wait... dism /English /Online /Get-Packages > "%TEMP%\packages.txt" echo Servicing stack update: KB3177467 call :exist .\%arch%\Windows6.1-KB3177467-%arch%.cab ||^ dism /Online /Add-Package /PackagePath:.\%arch%\Windows6.1-KB3177467-%arch%.cab /Quiet /NoRestart echo Convenience rollup update: KB3125574 call :exist .\%arch%\Windows6.1-KB3125574-v4-%arch%.cab ||^ dism /Online /Add-Package /PackagePath:.\%arch%\Windows6.1-KB3125574-v4-%arch%.cab /Quiet /NoRestart echo ------------------------------------------------------------------------------- pause :exist dism /English /Online /Get-PackageInfo /PackagePath:%1 | find "Package Identity" |^ findstr /g:/ %TEMP%\packages.txt > nul && exit /b exit /b 1 

Files and folders:
')
I don’t attach update package files here, as those listed in the script are taken for sample. At the location of the script, x64 and x86 folders should be created in which you need to place the necessary update packages. The script file itself can be saved in ANSI encoding if you do not use the Cyrillic alphabet to display informational messages. And if you want to see the Russian text, then you need to save the cmd-file in the OEM encoding 866 .

Description of work:

Before starting the installation, DISM will request ( / Get-Packages ]) the OS for the list of already installed service packs and save it in a text file in the % TEMP% \ packages.txt temporary folder. Later on, before starting the installation of each update package, the “function” is accessed : exist with the transfer as an argument - the path to the package being installed for verification. “Function” : exist retrieves ( / Get-PackageInfo ) service information from the package being checked, in which the “Package Identity” string is searched. This string “by pipeline” is passed to the next search command, which searches for the given string in the saved % TEMP% \ packages.txt file. According to the search results, two options are possible:


Possible problems:

Checking for updates in the OS is performed only in the “Package Identity” field, the status is not checked! In the normal state, the packages have the status of Installed (Installed), but erroneous states of the service packs present in the system are possible: Superseded ( Not replaced), Not Present (Not present ), Staged (Intermediate). The status of the present packages can be viewed by opening the % TEMP% \ packages.txt file created during the script operation. If there are no “erroneous” states, then there should be no problems: something should be established, and what is already installed will be missed.

Using this script to update the OS with missing packages saves a lot of time!

Source: https://habr.com/ru/post/340876/


All Articles