-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathremoveFeatures.bat
More file actions
301 lines (253 loc) · 7.61 KB
/
Copy pathremoveFeatures.bat
File metadata and controls
301 lines (253 loc) · 7.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
::
:: Remove some unwanted optional features
::
:: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/dism-capabilities-package-servicing-command-line-options?view=windows-11
::
:: vs 1.0.0
:: date 16.06.2025
::
@echo off
setlocal enabledelayedexpansion
set my_name=%~n0%~x0
set my_dir="%~dp0"
set "my_dir=%my_dir:~1,-2%"
set /a ACTION_REMOVE=1
set /a ACTION_ADD=2
set /a ACTION_CHECK=3
set /a ACTION_LIST=4
set /a action=%ACTION_CHECK%
set /a verbose=0
SET /a check_info_level=0
SET "flp=%tmp%\featureslist.txt"
set name=
set names=(^
DirectPlay^
LegacyComponents^
MediaPlayback^
MicrosoftWindowsPowerShellV2Root^
MicrosoftWindowsPowerShellV2^
Microsoft-RemoteDesktopConnection^
MSRDC-Infrastructure^
Printing-Foundation-Features^
Printing-Foundation-InternetPrinting-Client^
Printing-Foundation-LPDPrintService^
Printing-Foundation-LPRPortMonitor^
Printing-XPSServices-Features^
SMB1Protocol^
SMB1Protocol-Client^
SMB1Protocol-Server^
SmbDirect^
WCF-Services45^
WCF-TCP-PortSharing45^
WorkFolders-Client^
)
if [%1]==[] goto main
GOTO :ParseParams
:ParseParams
if [%1]==[/?] goto help
if [%1]==[/h] goto help
if [%1]==[/help] goto help
IF /i "%~1"=="/a" (
SET /a action=%ACTION_ADD%
goto reParseParams
)
IF /i "%~1"=="/add" (
SET /a action=%ACTION_ADD%
goto reParseParams
)
IF /i "%~1"=="/c" (
SET /a action=%ACTION_CHECK%
SET /a check_info_level=1
goto reParseParams
)
IF /i "%~1"=="/check" (
SET /a action=%ACTION_CHECK%
SET /a check_info_level=1
goto reParseParams
)
IF /i "%~1"=="/cx" (
SET /a action=%ACTION_CHECK%
SET /a check_info_level=2
goto reParseParams
)
IF /i "%~1"=="/check-extended" (
SET /a action=%ACTION_CHECK%
SET /a check_info_level=2
goto reParseParams
)
IF /i "%~1"=="/l" (
SET /a action=%ACTION_LIST%
goto reParseParams
)
IF /i "%~1"=="/list" (
SET /a action=%ACTION_LIST%
goto reParseParams
)
IF /i "%~1"=="/r" (
SET /a action=%ACTION_REMOVE%
goto reParseParams
)
IF /i "%~1"=="/remove" (
SET /a action=%ACTION_REMOVE%
goto reParseParams
)
IF /i "%~1"=="/n" (
SET "name=%~2"
SHIFT
goto reParseParams
)
IF /i "%~1"=="/name" (
SET "name=%~2"
SHIFT
goto reParseParams
)
IF /i "%~1"=="/v" (
SET /a verbose=1
goto reParseParams
)
IF /i "%~1"=="/h" (
goto help
)
:reParseParams
SHIFT
if [%1]==[] goto main
GOTO :ParseParams
:main
if %verbose% EQU 1 (
echo action: %action%
)
if %action% EQU %ACTION_REMOVE% (
if ["%name%"] NEQ [""] (
echo removing %name%
call :removeF "%name%"
) else (
for /d %%i in %names% do (
echo removing %%i
call :removeF "%%i"
echo.
echo.
)
)
) else if %action% EQU %ACTION_ADD% (
if ["%name%"] NEQ [""] (
echo adding %name%
call :addF "%name%"
) else (
for /d %%i in %names% do (
echo adding %%i
call :addF "%%i"
echo.
echo.
)
)
) else if %action% EQU %ACTION_CHECK% (
if ["%name%"] NEQ [""] (
echo checking %name%
call :checkF "%name%" %check_info_level%
) else (
for /d %%i in %names% do (
echo checking %%i
call :checkF "%%i" %check_info_level%
echo.
echo.
)
)
) else if %action% EQU %ACTION_LIST% (
echo listing capabilities
call :listF
) else (
echo [e] Mode %mode% is not supported!
goto mainend
)
:mainend
if exist "%flp%" del "%flp%"
endlocal
exit /b %errorlevel%
:removeF
setlocal
set "name=%~1"
set state=
for /f "tokens=3" %%i in ('powershell "DISM /Online /Get-Features | Select-String -Pattern "%name%$" -Context 0,2"') do (
set state=%%i
)
echo state=%state%
if [%state%] EQU [Enabled] (
DISM /Online /Disable-Feature /FeatureName:"%name%"
) else (
echo %state%
)
endlocal
exit /b %errorlevel%
:addF
setlocal
set "name=%~1"
set state=
for /f "tokens=3" %%i in ('powershell "DISM /Online /Get-Features | Select-String -Pattern "%name%$" -Context 0,2"') do (
set state=%%i
)
if [%state%] EQU [Disabled] (
DISM /Online /Enable-Feature /FeatureName:"%name%"
) else (
echo %state%
)
endlocal
exit /b %errorlevel%
:checkF
setlocal
set "name=%~1"
set /a check_info_level=%~2
if %check_info_level% EQU 1 (
powershell "DISM /Online /Get-Features | Select-String -Pattern "%name%$" -Context 0,2"
) else (
powershell "DISM /Online /Get-Features | Select-String -Pattern "%name%$" -Context 0,2"
)
endlocal
exit /b %errorlevel%
:listF
setlocal
DISM /Online /Get-Features
endlocal
exit /b %errorlevel%
:usage
echo Usage: %my_name% [/c^|cx^|/r^|/a] [/n ^<name^>] [/v] [/h]
exit /B 0
:help
call :usage
echo.
echo Targets: !! Not selectable, just for info !!
echo LegacyComponents : Controls legacy components in Windows.
echo DirectPlay : Enables the installation of DirectPlay component.
echo MediaPlabyack : Controls media features such as Windows Media Player,
echo MicrosoftWindowsPowerShellV2Root : Windows Powershell 2.0
echo MicrosoftWindowsPowerShellV2 : Windows Powershell 2.0
echo Microsoft-RemoteDesktopConnection : The Remote Desktop Connection application
echo MSRDC-Infrastructure : Remote Differential Compression (RDC) API Support for use in third-party applications.
echo Printing-XPSServices-Features
echo Printing-Foundation-Features : Enable print, fax, and scan tasks on this computer.
echo Printing-Foundation-InternetPrinting-Client : Enables clients to use HTTP to connect to printers on Web print servers.
echo Printing-Foundation-LPDPrintService : Makes your Windows computer work as a Line Printer Daemon (LPD) and Remote Line Printer client.
echo Printing-Foundation-LPRPortMonitor : Enables clients to print to TCP/IP printers connected to a UNIX (or VAX) server.
echo SmbDirect : Remote Direct Memory Access (RDMA) support for the SMB 3.x file sharing protocol.
echo SMB1Protocol : Support for the SMB 1.0/CIFS file sharing protocol, and the Computer Browser protocol.
echo SMB1Protocol-Client : Support for the SMB 1.0/CIFS client for accessing legacy servers.
echo SMB1Protocol-Server : Support for the SMB 1.0/CIFS file server for sharing data with legacy clients and browsing the network neighborhood.
echo WCF-Services45 : WCF-Services
echo WCF-TCP-PortSharing45 : TCP Port Sharing.
echo WorkFolders-Client : Allows file synchronization with a configured file server.
echo.
echo Actions:
echo /a : Add the feature(s).
echo /c : Check the feature(s) state.
echo /cx : Check the feature(s) complete info.
echo /l : List all features.
echo /r : Remove the feature(s).
echo.
echo Options:
echo /n : Name a specific arbitrary target.
echo.
echo Other:
echo /v: More verbose.
echo /h: Print this.
echo.
echo Defaults to check (/c) all targets.
exit /B 0