📜 ⬆️ ⬇️

Script for adding service packs to a Windows image

This article is a logical continuation of my previous article. Developing the theme of adding (installing / integrating) service packs into a Windows image I decided to write a script operating with DISM commands that automates the process and relieves system administrators from routine actions. The versatility of the script is that with its help, you can install service packs on a “live” system, or integrate it into a Windows image — the install.wim file. The flexibility of the script is that its work can be customized by changing the value of several variables at the beginning of the whole code.

As in the previous article, for example, we will add the so-called Convenience rollup update (KB3125574) to the Windows image, as well as the necessary Servicing stack update (KB3177467). During the work on the script, it turned out that after integration into the image KB3177467, it (the image - install.wim ) becomes unsuitable for further integrations. If you install KB3177467 on a “live” OS, then there are no problems. This problem has two solutions: 1) integrate KB3177467 with the latest 2) replace the “problem” update with its previous version - KB3020369. I chose the second option by implementing a branch in the script by condition.

Script


@echo off Title Convenience Rollup - most important updates after SP1 set _arch=x64 set _file=install.wim set _img=Online set _mnt=mount set _lev=2 :pre_menu cls dism /Get-WimInfo /LogLevel:%_lev% /WimFile:%_file% echo ------------------------------------------------------------------------------- if %ERRORLEVEL% NEQ 0 if %ERRORLEVEL% EQU 2 (goto :bit) else (pause & exit) set /p _ind=Input index or press [Enter] for quit: || exit if %_ind% EQU 0 goto :bit if %_ind% GTR 0 if %_ind% LEQ 24 goto :ind_menu goto :pre_menu :ind_menu cls dism /Get-WimInfo /LogLevel:%_lev% /WimFile:%_file% /Index:%_ind% echo ------------------------------------------------------------------------------- if %ERRORLEVEL% NEQ 0 pause & goto :pre_menu choice /c abcdefghijklmnopqrstuvwxyz /n /m "Mount selected image? [m] " if %ERRORLEVEL% EQU 13 goto :mount goto :pre_menu :bit if %_img%==Online (if "%PROCESSOR_ARCHITECTURE%" == "x86" if not defined PROCESSOR_ARCHITEW6432 set _arch=x86)^ else (dism /Get-WimInfo /LogLevel:%_lev% /WimFile:%_file% /Index:%_ind% /English | find "Architecture : x86" > nul && set _arch=x86) goto :add :add cls echo Getting packages list. Please wait... dism /%_img% /Get-Packages /LogLevel:%_lev% /English > %TEMP%\packages.txt echo ------------------------------------------------------------------------------- if not %_img%==Online ( echo Add: Servicing stack update KB3020369 call :exist .\%_arch%\Windows6.1-KB3020369-%_arch%.cab ||^ dism /%_img% /Add-Package /LogLevel:%_lev% /PackagePath:.\%_arch%\Windows6.1-KB3020369-%_arch%.cab /NoRestart echo ------------------------------------------------------------------------------- ) else ( echo Add: Servicing stack update KB3177467 call :exist .\%_arch%\Windows6.1-KB3177467-%_arch%.cab ||^ dism /%_img% /Add-Package /LogLevel:%_lev% /PackagePath:.\%_arch%\Windows6.1-KB3177467-%_arch%.cab /NoRestart echo ------------------------------------------------------------------------------- ) echo Add: Convenience rollup update KB3125574 call :exist .\%_arch%\Windows6.1-KB3125574-v4-%_arch%.cab ||^ dism /%_img% /Add-Package /LogLevel:%_lev% /PackagePath:.\%_arch%\Windows6.1-KB3125574-v4-%_arch%.cab /NoRestart echo ------------------------------------------------------------------------------- del %TEMP%\packages.txt if not exist %_file% exit pause goto :unmount :exist dism /%_img% /Get-PackageInfo /LogLevel:%_lev% /PackagePath:%1 /English | find "Package Identity" | findstr /g:/ %TEMP%\packages.txt > nul exit /b :mount cls md %_mnt% dism /Mount-Wim /LogLevel:%_lev% /WimFile:%_file% /Index:%_ind% /MountDir:%_mnt% if %ERRORLEVEL% NEQ 0 rd %_mnt% & pause & exit set _img=Image:%_mnt% goto :bit :unmount cls if not %_img%==Online ( dism /Unmount-Wim /LogLevel:%_lev% /MountDir:%_mnt% /Commit rd %_mnt% ) set _arch=x64 set _img=Online goto :pre_menu 

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 .

Using


As already noted, the script can install updates or integrate them. If there is no install.wim image file in the launch folder, the script performs the installation of updates in fully automatic mode. If there is an install file in the startup folder, install.wim , then the script reads information about it from the existing "indexes" and offers to enter a number. After that, extended information about the selected "index" is displayed, a request for mounting is issued. Pressing any key leads to a return, and pressing the [m] key launches the following chain of actions: mounting the image, integrating updates, unmounting the image, returning to the selection menu. Then you can choose another "index" for the integration of updates. Selecting the "index" at number 0 starts the installation of updates on the "live" OS.

Parsing code


At first, the set command sets the variables. You can change the estimated name of the install.wim image file (for example, to install.esd ). You can change the name of the mount folder or set the path if the mount folder should be outside the launch folder. You can change the logging level to exclude informational messages from the DISM system log file.
')

: pre_menu


Preliminary menu. Getting basic information about a wim file with error checking. If error 2 - there is no wim file, then start in Online mode. I did not find information about the maximum number of "indexes" in one image and set the value to 24.

: ind_menu


Index menu. Get extended information about the selected "index" in a wim file with error control. Offer to mount the "index".

: bit


Determining the bit OS. For interactive maintenance, system environment variables are read, and for offline maintenance, the necessary information is requested from the image and the key string is searched for in it.

: add


Adding packages. In order not to do any extra work, a list of already added (installed or integrated) packages is first requested, and then, before each start command, a pseudo-function is called to check.

: exist


Pseudo function check. The work is described in the article Checking the presence of a service pack on the system before installation . The code is slightly corrected.

: mount


Mounting image Pre-created mount folder. Error control. The variable defining the specification of the image changes, now points to the path to the autonomous image.

: unmount


Unmounting an image. If online maintenance was performed (/ Online), then it is not necessary to unmount it. Return of variables to initial values.

Compatibility


The operation of this script was tested on Windows 7 with the integrated utility dism.exe version 6.1.7600.16385. In versions of Windows 8, 8.1, 10, the dism.exe utility of the DISM system has a higher version. I think backward compatibility is preserved, and the script will also work. In addition, it will be possible to work with esd- files.

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


All Articles