Windows Component Disable Script
Continuing a series of articles on administering the Windows operating system. In the previous article, work was done with service packs, and in this one with system components. Additional components expand the functionality of the OS, but many of them are simply useless for most users. I suggest a convenient script that disables "unnecessary" components. Script commands access DISM tools and can be applied both to the installed system and to a standalone image. The script determines the version of dism.exe utility and substitutes the necessary commands. Branching is implemented according to the version of the target OS, so that in one script you can specify which components to disable for different versions of Windows.
Disabling components with this script is reversible. I do this mainly to remove links to programs I do not need from the Start menu. Here, for example, two components are specified for each version of Windows that will be disabled. Those who will use this script in their work need to supplement it. Identify the components that you do not need and add their disconnection to the script. By simple changes, you can vice versa - include components. For my needs, I leave only Internet Explorer, Media Player, Windows Search, and the .NET Framework 3.5.1. The latter is disabled by the manufacturer in new versions of Windows, with the deletion of files, and to enable it I have a separate script, which I will write about later.
This script can disable components both in an online system and in a standalone image. If there is no image file in the startup folder - install.wim , then the script disconnects the components in fully automatic mode. If there is an image file in the startup folder - install.wim, then the script reads from it information about the available "indexes" and offers to enter the number. After that, extended information about the selected “index” is displayed, a mounting request is issued. Pressing any key leads to a return, and pressing the [m] key starts the following chain of actions: mounting the image, disconnecting the components, unmounting the image, returning to the selection menu “indesk”. Then you can select another "index" to disable components. Selecting an "index" at number 0 starts disabling the components on a "live" OS.
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 specify the path if the mount folder should be outside the startup folder. I decided to refuse from setting the “level” of logging, as in the previous script for service packs, and directly prescribed information about errors only in all commands - / LogLevel: 1 . Also in all teams added the / English switch so that all messages are displayed in English.
The script can be run on different versions of the OS, and thus access different versions of the DISM systemwhich differ in a set of commands. So, in versions after 6.1 in all commands, the word Wim is replaced with Image , although the old “names” of commands are left for backward compatibility. At the very beginning of the script, the version of dism.exe is determined and in the future all the commands are substituted with the right word. It would be possible to do without determining the version, but I use this functionality in my script to get information from a Windows image, so I just did not rewrite the code.
Advance menu. Getting basic information about a wim file with error control. If the image file is missing, 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.
Index menu. Getting extended information about the selected “index” in a wim file with error control. The proposal to mount the "index".
Determining the version of the target system. If the necessary line is found, then the transition to the specified label is performed. If the string is not found, then unmount.
Labels of targeted service systems. I call Windows 8.1 - nine, and Windows 10 - Windows A (anyone who understands the topic), so these names are on the labels. At the beginning of this block, the status of all components is requested and saved to the features.txt file . In the future, in order to speed up the disconnection process and not try to disconnect what is already disconnected, a preliminary check of the state of each component occurs. At the end of the block is the removal of temporary files and unmounting.
Checking the status of a component. A pseudo-function that returns the result by the error code to the global variable % ERRORLEVEL% . The string with the name of the component is looked up in the features.txt file and if the word “Enable” is found and also found, then the signal is turned off.
Mount image. The mount folder is pre-created. Error control. The variable that defines the specification of the image changes, now it points to the path to the offline image.
Unmount an image. If you performed online maintenance (/ Online), you do not need to unmount. Returning variables to their original values.
When servicing an image of a higher version on a system of a lower version, freezes and errors are possible. That is, you do not need to try on Windows 7 to process the Windows 8.1 or 10 image file. Also, for successful execution of all commands, you need to disable User Account Control - set the EnableLUA parameter to 0.
I turn off all the components associated with printing, while my printer continues to print, and the scanner continues to scan. I assume that the printing components (for example, Printing-Foundation-Features , etc.) are used for advanced features - for example, for setting up a printer accessible on a network. Is it so?
Disabling components with this script is reversible. I do this mainly to remove links to programs I do not need from the Start menu. Here, for example, two components are specified for each version of Windows that will be disabled. Those who will use this script in their work need to supplement it. Identify the components that you do not need and add their disconnection to the script. By simple changes, you can vice versa - include components. For my needs, I leave only Internet Explorer, Media Player, Windows Search, and the .NET Framework 3.5.1. The latter is disabled by the manufacturer in new versions of Windows, with the deletion of files, and to enable it I have a separate script, which I will write about 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 an online system and in a standalone image. If there is no image file in the startup folder - install.wim , then the script disconnects the components in fully automatic mode. If there is an image file in the startup folder - install.wim, then the script reads from it information about the available "indexes" and offers to enter the number. After that, extended information about the selected “index” is displayed, a mounting request is issued. Pressing any key leads to a return, and pressing the [m] key starts the following chain of actions: mounting the image, disconnecting the components, unmounting the image, returning to the selection menu “indesk”. Then you can select another "index" to disable components. Selecting an "index" at number 0 starts disabling the components on a "live" OS.
Code parsing
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 specify the path if the mount folder should be outside the startup folder. I decided to refuse from setting the “level” of logging, as in the previous script for service packs, and directly prescribed information about errors only in all commands - / LogLevel: 1 . Also in all teams added the / English switch so that all messages are displayed in English.
The script can be run on different versions of the OS, and thus access different versions of the DISM systemwhich differ in a set of commands. So, in versions after 6.1 in all commands, the word Wim is replaced with Image , although the old “names” of commands are left for backward compatibility. At the very beginning of the script, the version of dism.exe is determined and in the future all the commands are substituted with the right word. It would be possible to do without determining the version, but I use this functionality in my script to get information from a Windows image, so I just did not rewrite the code.
: pre_menu
Advance menu. Getting basic information about a wim file with error control. If the image file is missing, 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. Getting extended information about the selected “index” in a wim file with error control. The proposal to mount the "index".
: version
Determining the version of the target system. If the necessary line is found, then the transition to the specified label is performed. If the string is not found, then unmount.
: disable-7: disable-9: disable-A
Labels of targeted service systems. I call Windows 8.1 - nine, and Windows 10 - Windows A (anyone who understands the topic), so these names are on the labels. At the beginning of this block, the status of all components is requested and saved to the features.txt file . In the future, in order to speed up the disconnection process and not try to disconnect what is already disconnected, a preliminary check of the state of each component occurs. At the end of the block is the removal of temporary files and unmounting.
: state
Checking the status of a component. A pseudo-function that returns the result by the error code to the global variable % ERRORLEVEL% . The string with the name of the component is looked up in the features.txt file and if the word “Enable” is found and also found, then the signal is turned off.
: mount
Mount image. The mount folder is pre-created. Error control. The variable that defines the specification of the image changes, now it points to the path to the offline image.
: unmount
Unmount an image. If you performed online maintenance (/ Online), you do not need to unmount. Returning variables to their original values.
Possible problems
When servicing an image of a higher version on a system of a lower version, freezes and errors are possible. That is, you do not need to try on Windows 7 to process the Windows 8.1 or 10 image file. 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 the components associated with printing, while my printer continues to print, and the scanner continues to scan. I assume that the printing components (for example, Printing-Foundation-Features , etc.) are used for advanced features - for example, for setting up a printer accessible on a network. Is it so?