Continuing a series of articles on the administration of the Windows operating system. In the previous
article, work was done with service packs, and in this one with system components. Additional components extend the functionality of the OS, but many of them are simply useless for most users. I offer a convenient script that disables "unnecessary" components. Script commands refer to the
DISM tools and can be applied to both the installed system and the offline image. The script determines the version of the
dism.exe utility and substitutes the necessary commands. Implemented branching according to the version of the target OS, so that in one script you can specify the components to be disabled for different versions of Windows.
Disabling components of this script is reversible. I mainly do this in order to remove links to unnecessary programs from the Start menu. Here, for example, there are two components for each version of Windows that will be disabled. Those who will use this script in their work need to supplement it. Determine the components that you do not need and add their disabling to the script. By simple changes, it is possible on the contrary - to include components. For my needs, I leave only Internet Explorer, Media Player, Windows Search and .NET Framework 3.5.1. The latter is disabled by the manufacturer in new versions of Windows, with the deletion of files, and in order to enable it I have a separate script about which I will write later.
Script
@echo off title Disabling features in Windows image set _file=install.wim set _img=Online set _mnt=mount set _tool=7 set _word=Wim dism /English /LogLevel:1 /Get-Help | find "Version: 6.1" > nul || set _tool=8 if %_tool% GTR 7 set _word=Image :pre_menu cls if not exist %_file% goto :version dism /English /LogLevel:1 /Get-%_word%Info /%_word%File:%_file% echo ------------------------------------------------------------------------------- if %ERRORLEVEL% NEQ 0 pause & exit set /p _ind=Input index or press [Enter] for quit: || exit if %_ind% EQU 0 goto :version if %_ind% GTR 0 if %_ind% LEQ 24 goto :ind_menu goto :pre_menu :ind_menu cls dism /English /LogLevel:1 /Get-%_word%Info /%_word%File:%_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 :version dism /%_img% /English /LogLevel:1 /Get-Help | find "Image Version: 6.1" > nul && goto :disable-7 dism /%_img% /English /LogLevel:1 /Get-Help | find "Image Version: 6.3" > nul && goto :disable-9 dism /%_img% /English /LogLevel:1 /Get-Help | find "Image Version: 10" > nul && goto :disable-A goto :unmount :disable-7 cls echo Getting list of features. Please wait... dism /%_img% /English /LogLevel:1 /Get-Features /Format:Table > %TEMP%\features.txt echo ------------------------------------------------------------------------------- set /a _num+=1 echo %_num% Disable: WindowsGadgetPlatform call :state WindowsGadgetPlatform &&^ dism /%_img% /English /LogLevel:1 /Disable-Feature /FeatureName:WindowsGadgetPlatform /NoRestart echo ------------------------------------------------------------------------------- set /a _num+=1 echo %_num% Disable: MediaCenter call :state MediaCenter &&^ dism /%_img% /English /LogLevel:1 /Disable-Feature /FeatureName:MediaCenter /NoRestart echo ------------------------------------------------------------------------------- del %TEMP%\features.txt if not exist %_file% exit goto :unmount :disable-9 cls echo Getting list of features. Please wait... dism /%_img% /English /LogLevel:1 /Get-Features /Format:Table > %TEMP%\features.txt echo ------------------------------------------------------------------------------- set /a _num+=1 echo %_num% Disable: Printing-Foundation-Features call :state Printing-Foundation-Features &&^ dism /%_img% /English /LogLevel:1 /Disable-Feature /FeatureName:Printing-Foundation-Features /NoRestart echo ------------------------------------------------------------------------------- set /a _num+=1 echo %_num% Disable: Windows-Defender-Default-Definitions call :state Windows-Defender-Default-Definitions &&^ dism /%_img% /English /LogLevel:1 /Disable-Feature /FeatureName:Windows-Defender-Default-Definitions /NoRestart echo ------------------------------------------------------------------------------- del %TEMP%\features.txt if not exist %_file% exit goto :unmount :disable-A cls echo Getting list of features. Please wait... dism /%_img% /English /LogLevel:1 /Get-Features /Format:Table > %TEMP%\features.txt echo ------------------------------------------------------------------------------- set /a _num+=1 echo %_num% Disable: MicrosoftWindowsPowerShellV2Root call :state MicrosoftWindowsPowerShellV2Root &&^ dism /%_img% /English /LogLevel:1 /Disable-Feature /FeatureName:MicrosoftWindowsPowerShellV2Root /NoRestart echo ------------------------------------------------------------------------------- set /a _num+=1 echo %_num% Disable: NetFx4-AdvSrvs call :state NetFx4-AdvSrvs &&^ dism /%_img% /English /LogLevel:1 /Disable-Feature /FeatureName:NetFx4-AdvSrvs /NoRestart echo ------------------------------------------------------------------------------- del %TEMP%\features.txt if not exist %_file% exit goto :unmount :state findstr %1 %TEMP%\features.txt | find "Enable" > nul exit /b :mount cls md %_mnt% dism /English /LogLevel:1 /Mount-%_word% /%_word%File:%_file% /Index:%_ind% /MountDir:%_mnt% if %ERRORLEVEL% NEQ 0 rd %_mnt% & pause & exit set _img=Image:%_mnt% goto :version :unmount cls if not %_img%==Online ( dism /English /LogLevel:1 /Unmount-%_word% /MountDir:%_mnt% /Commit rd %_mnt% ) set _img=Online goto :pre_menu
Using
This script can disable components both in the online system and in the offline image. If there is no
install.wim image file in the launch folder, the script will disable the components 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, disabling components, unmounting the image, returning to the selection menu. Then you can select another "index" to disable components. Selecting "index" at number 0 starts disabling components on a 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. From the installation of the “level” of logging, as in the previous script on the update packages, I decided to refuse and directly registered in all commands informing only about errors -
/ LogLevel: 1 . Also, in all commands I added the
/ English key so that all messages are displayed in English.
')
The script can be run on different versions of the OS, and thus refer to different versions of the
DISM system, which differ in the set of commands. So, in versions after
6.1 in all commands, the word
Wim is replaced by
Image , although the old “names” of commands are left for backward compatibility. At the very beginning of the script, the version of the
dism.exe utility is
determined and, in the future, the necessary word is substituted into all the commands. It would have been possible to do without determining the version, but I use this functionality in my script for retrieving information from a Windows image, so I simply did not rewrite the code.
: pre_menu
Preliminary menu. Getting basic information about a
wim file with error checking. If there is no image file, then run 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".
: version
Determining the version of the target system. If the required string is found, then go to the specified label. If the string is not detected, then unmount occurs.
: disable-7: disable-9: disable-A
Labels target service systems. I call Windows 8.1 - nine, and Windows 10 - Windows A (who understands the topic), so these labels have names. At the beginning of this block, the status of all components is queried and saved in the
features.txt file. Later, in order to speed up the shutdown process and not try to disable something that is already disabled, a preliminary check of the state of each component takes place. At the end of the block - delete temporary files and unmount.
: state
Check component status. Pseudo-function that returns the result by error code in the global variable
% ERRORLEVEL% . The line with the name of the component is searched in the
features.txt file and if the word “Enable” is found and also found, then the signal is turned off.
: 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.
Possible problems
When servicing the image of the higher version on the system of the lower version, there may be hangs and errors. That is, you do not need to try to process the Windows 8.1 or 10 image file on Windows 7. Also, for successful execution of all commands, you need to disable User Account Control - set the
EnableLUA parameter to 0.
Question
I turn off all components related to printing and at the same time my printer continues to print and the scanner to scan. I assume that print components (for example,
Printing-Foundation-Features and others) are used for advanced features — for example, to set up a printer accessible over a network. Is it so?