View difference between Paste ID: Ey7ycVsP and gNsLEWJe
SHOW: | | - or go back to the newest paste.
1
@set @version=10.5 /* &title Windows Update Toggle
2
@echo off
3-
exit /b [OUTDATED] 
3+
4
echo      ---------------------------------------------------------------------
5
echo     :                     Windows Update Toggle v10.5                     :
6
echo     :---------------------------------------------------------------------:
7
echo     :         Block/Enable Upgrades, Installs, Downloads, Service         :
8
echo     :         Disable/Enable Reports, Speech, SearchUI, Defender          :
9
echo     :        Hide/Unhide/Apply update lists with count and max size       :
10
echo     :         Preset Defender updates and Store downloads working         :
11
echo     :                                                                     :
12
echo     :     Toggle from the comfort of Desktop right-click context menu     :
13
echo      ---------------------------------------------------------------------
14
echo.
15
:: 2020-09-07 v10.4: downloads option fixed and selected by default. stay tuned for a redesigned version with less hard blocks
16
:: 2018-05-15 v10.1: streamlined toggling with a nicer gui
17
:: Focus set on Defender updates working independently from windows mayhem automatic updates
18
:: so this script will not sacrifice built-in protection layer, unlike most other -DIY- updates "management" just killing wuauserv
19
:: Update lists will be refreshed whenever Windows would nag -and-force-reboot- via MusNotification (hijacked)
20
:: had to use separate context menus for each category due to limitation of max 16 cascading items.. tx bill gates, 2018
21
:: if Defender protection updates are detected in the Apply list, a manual signature update is set to trigger
22
:: SearchUI option will disable start menu search - obviously, but you can use Classic Shell instead to have it working
23
:: Disable option provided for wuauserv, but not recommended since a lot of stuff depends on it
24
:: Mostly IFEO safe blocking with no destructive changes of ownership, deleting files, removing tasks, or over-blocking
25
:: Troubleshooter option will just revert blocking done by this and former suite scripts; launches official update troubleshooter
26
:: If blocking caused an unlikely logon issue, do advanced startup-troubleshoot-commandprompt and run WUTUndo.bat from C:\Windows
27
:: There is a lot of ping-pong in the backend between CMD and WScript to bypass popups and prompts, yet neatly structured script
28
:: AveYo, 2018-05-13
29
30
if %1.==. timeout /t 10 &call wscript /e:JScript "%~f0" runas setup &exit &rem : no arguments, run setup elevated
31
if %1.==shift. shift &shift &rem : if loaded by WScript, shift args to prevent loop and restore %0
32
if %1.==. echo ERROR! &timeout /t 5 &exit/b : must have at least one arg
33
34
:: Setup executable blocking via ifeo
35
set notifier=EOSNotify MusNotification
36
set upgrader=Windows10UpgraderApp Windows10Upgrade WindowsUpdateBox SetupHost setupprep
37
set installer=wuauclt
38
set downloader=MoUsoCoreWorker sedlauncher sedsvc
39
set reporter=wermgr wsqmcons DiagTrackRunner DiagnosticsHub.StandardCollector.Service CompatTelRunner
40
set speecher=SpeechRuntime SpeechModelDownload
41
set searcher=SearchUI
42
43
set "exe=%notifier% %upgrader% %installer% %downloader% %reporter%"
44
set "noop=%SystemRoot%\system32\systray.exe"
45
set "ifeo=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
46
set "wut=HKCR\DesktopBackground\shell\WUT"
47
set "menu=%wut%\shell"
48
set "f0=%SystemRoot%\windows_update_toggle.bat"
49
set ".=>nul 2>nul"
50
set "verbose="
51
52
for /f "tokens=2 delims=1234567890" %%a in ('shutdown /?^|findstr /bc:"E"') do set "[T]=%%a" &rem : cosmetic usage in menus
53
if defined verbose (echo on &set ".=" &set "window=") else set "window=hide"
54
call :%~1 %2 %3 %4 %5 %6 %7 %8 %9 &rem : launch secondary functions below dinamically, passing next args
55
echo.
56
echo Done! Use the Desktop right-click context menu to toggle, renew or uninstall
57
if "%~1"=="setup" (pause) else if defined verbose timeout /t 5
58
59
exit/b : End of main script, functions below
60
::---------------------------------------------------------------------------------------------------------------------------------
61
62
:refresh context menu
63
echo %0 %*
64
call :reg_query "HKLM\SOFTWARE\WUT.bat" NoBlock noblock
65
if "%noblock%"=="Enable" exit/b
66
call :reg_query "%wut%0pending" MUIVerb pending
67
if defined pending exit/b
68
for %%a in ("1hide" "2unhide" "3apply") do reg delete "%wut%%%~a" /f %.%
69
reg add "%wut%0pending" /v MUIVerb /d "Pending.." /f %.%
70
reg add "%wut%0pending" /v Icon /d "ieframe.dll,11" /f %.%
71
reg add "%wut%0pending" /v SubCommands /d "" /f %.%
72
call :reg_query "HKLM\SOFTWARE\WUT.bat" NoRefresh norefresh
73
if "%norefresh%"=="Disable" (set "toggle=39") else set "toggle=38"
74
reg add "%menu%\2Lists"  /v Icon /d "ieframe.dll,%toggle%" /f %.%
75
if "%norefresh%"=="Disable" start "WUT" wscript /e:JScript "%f0%" WUTRefresh
76
call :status SetupHost 3Upgrades
77
call :status wuauclt 4Installs
78
call :status MoUsoCoreWorker 5Downloads
79
rem for /f "tokens=3" %%a in ('sc qc TrustedInstaller ^| find /I "WUTblocked"') do set "blocked=%%a"
80
rem if /i "%blocked%"=="[WUTblocked]" (set "toggle=38") else set "toggle=39"
81
rem reg add "%menu%\5Downloads"  /v Icon /d "ieframe.dll,%toggle%" /f %.%
82
for /f "tokens=3" %%a in ('sc qc wuauserv ^| find /I "WUTblocked"') do set "blocked=%%a"
83
if /i "%blocked%"=="rpcss[WUTblocked]" (set "toggle=38") else set "toggle=39"
84
reg add "%menu%\6Service"  /v Icon /d "ieframe.dll,%toggle%" /f %.%
85
call :status wermgr 81Report
86
call :status SpeechRuntime 82Speech
87
call :status SearchUI 83Search
88
set "defstatus=if((Get-MpPreference).DisableRealtimeMonitoring){write-host 38}else{write-host 39}"
89
for /f "delims=" %%a in ('call powershell.exe -c "%defstatus%;"') do set "toggle=%%a"
90
reg add "%menu%\84Defender"  /v Icon /d "ieframe.dll,%toggle%" /f %.%
91
if "%norefresh%"=="Enable" reg delete "%wut%0pending" /f %.%
92
exit/b
93
94
:status %1:exe %2:submenu
95
call :reg_query "%ifeo%\%~1.exe" Debugger block
96
if defined block (set "toggle=38") else set "toggle=39"
97
reg add "%menu%\%~2"  /v Icon /d "ieframe.dll,%toggle%" /f %.%
98
exit/b
99
100
:flip %1:exe %2:submenu
101
call :reg_query "%ifeo%\%~1.exe" Debugger block
102
if defined block (set "toggle=39") else set "toggle=38"
103
reg add "%menu%\%~2"  /v Icon /d "ieframe.dll,%toggle%" /f %.%
104
exit/b
105
106
:toggle WUT
107
echo %0 %*
108
call :reg_query "HKLM\SOFTWARE\WUT.bat" NoBlock noblock
109
if "%noblock%"=="Disable" (set "toggle=Enable") else set "toggle=Disable"
110
for %%a in (NoBlock NoRefresh) do reg add "HKLM\SOFTWARE\WUT.bat" /v %%a /d "%toggle%" /f %.%
111
set "task=wscript.exe /e:JScript \"%f0%\" schtasks WUT"
112
:: Generate WUT main context menu
113
for %%a in ("" "0pending" "1hide" "2unhide" "3apply") do reg delete "%wut%%%~a" /f %.%
114
reg add "%wut%" /v MUIVerb /d "Windows Update Toggle" /f %.%
115
reg add "%wut%" /v Icon /d "comres.dll,4" /f %.%
116
reg add "%wut%" /v SubCommands /d "" /f %.%
117
reg add "%menu%\9Setup" /v MUIVerb /d "Configure WUT v%@version:~0,4%" /f %.%
118
reg add "%menu%\9Setup" /v SubCommands /d "" /f %.%
119
reg add "%menu%\9Setup\shell\1Toggle"  /v MUIVerb /d "%toggle%" /f %.%
120
reg add "%menu%\9Setup\shell\2Renew"   /v MUIVerb /d "Renew" /f %.%
121
reg add "%menu%\9Setup\shell\3Remove"  /v MUIVerb /d "Remove" /f %.%
122
reg add "%menu%\9Setup\shell\1Toggle\command" /ve /d "%task%\toggle" /f %.%
123
reg add "%menu%\9Setup\shell\2Renew\command"  /ve /d "%task%\renew" /f %.%
124
reg add "%menu%\9Setup\shell\3Remove\command" /ve /d "%task%\remove" /f %.%
125
if "%toggle%"=="Disable" (
126
 reg add "%menu%\1Refresh"    /v MUIVerb /d "Refresh" /f %.%
127
 reg add "%menu%\2Lists"      /v MUIVerb /d "Lists" /f %.%
128
 reg add "%menu%\3Upgrades"   /v MUIVerb /d "Upgrades %[T]% setuphost" /f %.%
129
 reg add "%menu%\4Installs"   /v MUIVerb /d "Installs %[T]% wuauclt" /f %.%
130
 reg add "%menu%\5Downloads"  /v MUIVerb /d "Downloads ! %[T]% trustedinstaller" /f %.%
131
 reg add "%menu%\6Service"    /v MUIVerb /d "Service ! ! %[T]% wuauserv" /f %.%
132
 reg add "%menu%\7Repair"     /v MUIVerb /d "Troubleshooter" /f %.%
133
 reg add "%menu%\81Report"    /v MUIVerb /d "Report" /f %.%
134
 reg add "%menu%\82Speech"    /v MUIVerb /d "Speech" /f %.%
135
 reg add "%menu%\83Search"    /v MUIVerb /d "SearchUI" /f %.%
136
 reg add "%menu%\84Defender"  /v MUIVerb /d "Defender" /f %.%
137
 reg add "%menu%\1Refresh\command" /ve   /d "%task%\refresh" /f %.%
138
 reg add "%menu%\2Lists\command" /ve     /d "%task%\lists" /f %.%
139
 reg add "%menu%\3Upgrades\command" /ve  /d "%task%\upgrades" /f %.%
140
 reg add "%menu%\4Installs\command" /ve  /d "%task%\installs" /f %.%
141
 reg add "%menu%\5Downloads\command" /ve /d "%task%\downloads" /f %.%
142
 reg add "%menu%\6Service\command" /ve   /d "%task%\service" /f %.%
143
 reg add "%menu%\7Repair\command" /ve    /d "%task%\repair" /f %.%
144
 reg add "%menu%\81Report\command" /ve   /d "%task%\report" /f %.%
145
 reg add "%menu%\82Speech\command" /ve   /d "%task%\speech" /f %.%
146
 reg add "%menu%\83Search\command" /ve   /d "%task%\search" /f %.%
147
 reg add "%menu%\84Defender\command" /ve /d "%task%\defender" /f %.%
148
)
149
:: Toggle immersive context-menu crap
150
::if "%toggle%"=="Disable" set "icm=0x0" else set "icm=0x1"
151
::reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\FlightedFeatures" /v ImmersiveContextMenu /t REG_DWORD /d %icm% /f %.%
152
:: Disabling automatic updates hinders Defender, so get definitions from MMPC first
153
set "DefMUS={MicrosoftUpdateServer|MMPC|InternalDefinitionUpdateServer}"
154
set "DefMMPC={MMPC|MicrosoftUpdateServer|InternalDefinitionUpdateServer}"
155
if "%toggle%"=="Enable" ( set "DefSig=%DefMUS%" ) else set "DefSig=%DefMMPC%"
156
start "WUT:MpPref" wscript /e:JScript "%~f0" cmd "powershell.exe -c `Set-MpPreference -SignatureFallbackOrder %DefSig%;`"
157
:: Default services
158
sc config wuauserv type= share depend= rpcss %.%
159
sc config TrustedInstaller type= own depend= / %.%
160
:: Toggle ifeo exe blocking
161
for %%a in (%exe% %speech% %search%) do reg delete "%ifeo%\%%a.exe" /f %.%
162
if "%toggle%"=="Enable" exit/b WUT disabled, so skip the code below
163
for %%a in (%exe%) do reg add "%ifeo%\%%a.exe" /v Debugger /d "%noop%" /f %.% &taskkill /im "%%a.exe" /t /f %.%
164
:: Block downloads on older version - a mess atm
165
net stop TrustedInstaller %.%
166
sc config TrustedInstaller type= own depend= [WUTblocked] %.%
167
:: WUTRefresh hijacking
168
for %%a in (MusNotification EOSNotify) do reg add "%ifeo%\%%a.exe" /v Debugger /d "%SystemRoot%\WUTRefresh.bat" /f %.%
169
call :refresh menu
170
exit/b
171
172
:hide update
173
echo %0 %*
174
call :reg_query "%wut%1hide\shell\%~1" MUIVerb updatefound
175
echo -%updatefound%
176
if not defined updatefound exit/b
177
call wscript /e:JScript "%f0%" hide "%updatefound%"
178
exit/b
179
180
:unhide update
181
echo %0 %*
182
call :reg_query "%wut%2unhide\shell\%~1" MUIVerb updatefound
183
echo -%updatefound%
184
if not defined updatefound exit/b
185
call wscript /e:JScript "%f0%" unhide "%updatefound%"
186
exit/b
187
188
:apply update
189
echo %0 %*
190
call :reg_query "%wut%3apply\shell\%~1" MUIVerb updatefound
191
echo -%updatefound%
192
if not defined updatefound exit/b
193
:: Cache current blocks status, because Apply will unblock downloads and installs in the WScript stage
194
call :reg_query "%ifeo%\wuauclt.exe" Debugger installs_blocked
195
call :reg_query "%ifeo%\MoUsoCoreWorker.exe" Debugger downloads_blocked
196
rem for /f "tokens=3" %%a in ('sc qc TrustedInstaller ^| find /I "WUTblocked"') do set "downloads_blocked=%%a"
197
call wscript /e:JScript "%f0%" apply "%updatefound%"
198
:: Restore cached blocks
199
if defined installs_blocked reg add "%ifeo%\wuauclt.exe" /v Debugger /d "%noop%" /f %.% &taskkill /im "wuauclt.exe" /t /f %.%
200
if defined downloads_blocked (
201
 reg add "%ifeo%\MoUsoCoreWorker.exe" /v Debugger /d "%noop%" /f %.%
202
 taskkill /im "MoUsoCoreWorker.exe" /t /f %.%
203
 reg add "%ifeo%\sedlauncher.exe" /v Debugger /d "%noop%" /f %.%
204
 taskkill /im "sedlauncher.exe" /t /f %.%
205
 reg add "%ifeo%\sedsvc.exe" /v Debugger /d "%noop%" /f %.%
206
 taskkill /im "sedsvc.exe" /t /f %.%
207
)
208
if defined downloads_blocked sc config TrustedInstaller type= own depend= [WUTblocked] %.%
209
exit/b
210
211
:lists
212
echo %0 %*
213
call :reg_query "HKLM\SOFTWARE\WUT.bat" NoRefresh norefresh
214
if "%norefresh%"=="Disable" ( set "norefresh=Enable" &set "toggle=38") else set "norefresh=Disable" &set "toggle=39"
215
reg add "HKLM\SOFTWARE\WUT.bat" /v NoRefresh /d "%norefresh%" /f %.%
216
reg add "%menu%\2Lists"  /v Icon /d "ieframe.dll,%toggle%" /f %.%
217
if "%norefresh%"=="Enable" (
218
 reg delete "%wut%1hide" /f %.% &reg delete "%wut%2unhide" /f %.% &reg delete "%wut%3apply" /f %.%
219
 reg delete "%wut%0pending" /f %.%
220
)
221
call :refresh lists
222
exit/b
223
224
:upgrades
225
echo %0 %*
226
call :flip SetupHost 3Upgrades
227
for %%a in (%upgrader%) do if defined block (
228
 reg delete "%ifeo%\%%a.exe" /f %.%
229
) else (
230
 reg add "%ifeo%\%%a.exe" /v Debugger /d "%noop%" /f %.% &taskkill /im "%%a.exe" /t /f %.%
231
)
232
exit/b
233
234
:installs
235
echo %0 %*
236
call :flip wuauclt 4Installs
237
for %%a in (%installer%) do if defined block (
238
 do reg delete "%ifeo%\%%a.exe" /f %.%
239
) else (
240
 reg add "%ifeo%\%%a.exe" /v Debugger /d "%SystemRoot%\WUTRefresh.bat" /f %.% &taskkill /im "%%a.exe" /t /f %.%
241
)
242
if defined block start "wut" wscript /e:JScript "%f0%" WUTRefresh
243
exit/b
244
245
:downloads
246
echo %0 %*
247
net stop TrustedInstaller /y %.%
248
call :reg_query "%wut%3apply" MUIVerb pending
249
set "reboot=%pending:reboot=%"
250
if defined pending if "%pending%"=="%reboot%" set "pending="
251
if defined pending (
252
 for %%a in (%downloader%) do reg delete "%ifeo%\%%a.exe" /f %.%
253
 sc config TrustedInstaller type= own depend= / %.%
254
 reg add "%menu%\5Downloads"  /v Icon /d "ieframe.dll,11" /f %.%
255
 exit/b
256
)
257
call :flip MoUsoCoreWorker 5Downloads
258
for %%a in (%downloader%) do if defined block (
259
 do reg delete "%ifeo%\%%a.exe" /f %.%
260
 for /f "tokens=3" %%a in ('sc queryex TrustedInstaller ^| find /i "PID"') do if not "%%a"=="0" taskkill /pid %%a /f %.%
261
 sc config TrustedInstaller type= own depend= [WUTblocked] %.%
262
) else (
263
 reg add "%ifeo%\%%a.exe" /v Debugger /d "%SystemRoot%\WUTRefresh.bat" /f %.% &taskkill /im "%%a.exe" /t /f %.%
264
 sc config TrustedInstaller type= own depend= / %.%
265
)
266
if defined block start "wut" wscript /e:JScript "%f0%" WUTRefresh
267
exit/b
268
269
:service
270
echo %0 %*
271
for /f "tokens=3" %%a in ('sc qc wuauserv ^| find /I "WUTblocked"') do set "blocked=%%a"
272
if /i "%blocked%"=="rpcss[WUTblocked]" (set "blocked=rpcss" &set "toggle=39") else set "blocked=rpcss[WUTblocked]" &set "toggle=38"
273
reg add "%menu%\6Service"  /v Icon /d "ieframe.dll,%toggle%" /f %.%
274
net stop wuauserv /y %.%
275
for /f "tokens=3" %%a in ('sc queryex wuauserv ^| find /i "PID"') do set "pid=%a"
276
if not "%pid%"=="0" taskkill /pid %pid% /f %.%
277
sc config wuauserv type= share depend= %blocked% %.%
278
if defined block start "wut" wscript /e:JScript "%f0%" WUTRefresh
279
exit/b
280
281
:repair
282
echo %0 %*
283
:: Restore services (undo only the changes made by this script, not whatever blocking was done by other means)
284
sc config wuauserv type= share depend= rpcss %.%
285
sc config TrustedInstaller type= own depend= / %.%
286
:: Remove any IFEO blocking done by past scripts
287
set eo=DiagnosticsHub.StandardCollector.Service WindowsUpdateElevatedInstaller LocationNotificationWindows InstallAgentUserBroker
288
set eo=%eo% UpdateNotificationMgr DataUsageLiveTileTask Windows10UpgraderApp WindowsActionDialog SpeechModelDownload WerFaultSecure
289
set eo=%eo% GetCurrentRollback WindowsUpdateBox Windows10Upgrade TrustedInstaller MusNotification DiagTrackRunner CompatTelRunner
290
set eo=%eo% WinREBootApp64 WinREBootApp32 UNPUXLauncher SpeechRuntime MusNotifyIcon PilotshubApp InstallAgent dstokenclean wsqmcons
291
set eo=%eo% disksnapshot osrssupdate wuapihost WaaSMedic UsoClient UNPUXHost SIHClient setupprep SetupHost osrssinst EOSNotify wusa
292
set eo=%eo% WerFault TiWorker SearchUI DWTRIG20 dusmtask dmclient appidtel wuauclt wermgr DFDWiz remsh reach HxTsr DWWIN DW20 GWX
293
set eo=%eo% MoUsoCoreWorker sedlauncher sedsvc
294
for %%a in (%eo%) do reg delete "%ifeo%\%%a.exe" /f %.%
295
:: Restore notification hijacking
296
>"%SystemRoot%\WUTRefresh.bat" echo/@start "WUTRefresh" /min wscript.exe /e:JScript "%f0%" WUTRefresh
297
for %%a in (MusNotification EOSNotify) do reg add "%ifeo%\%%a.exe" /v Debugger /d "%SystemRoot%\WUTRefresh.bat" /f %.%
298
:: Remove pending instance safeguard
299
reg delete "HKLM\SOFTWARE\WUT.bat" /v Pending /f %.%
300
:: Refresh menu
301
call :refresh repair
302
:: Open Update Diagnostic
303
start "wud" msdt.exe /id WindowsUpdateDiagnostic %.%
304
:: Open official update troubleshooter page
305
start https://support.microsoft.com/en-us/help/4027322/windows-update-troubleshooter %.%
306
exit/b
307
308
:report
309
echo %0 %*
310
call :flip wermgr 81Report
311
for %%a in (%reporter%) do if defined block ( reg delete "%ifeo%\%%a.exe" /f %.% ) else (
312
 reg add "%ifeo%\%%a.exe" /v Debugger /d "%noop%" /f %.% &taskkill /im "%%a.exe" /t /f %.%
313
)
314
exit/b
315
316
:speech
317
echo %0 %*
318
call :flip SpeechRuntime 82Speech
319
for %%a in (%speecher%) do if defined block ( reg delete "%ifeo%\%%a.exe" /f %.% ) else (
320
 reg add "%ifeo%\%%a.exe" /v Debugger /d "%noop%" /f %.% &taskkill /im "%%a.exe" /t /f %.%
321
)
322
exit/b
323
324
:search
325
echo %0 %*
326
call :flip SearchUI 83Search
327
for %%a in (%searcher%) do if defined block ( reg delete "%ifeo%\%%a.exe" /f %.% ) else (
328
 reg add "%ifeo%\%%a.exe" /v Debugger /d "%noop%" /f %.% &taskkill /im "%%a.exe" /t /f %.%
329
)
330
exit/b
331
332
:defender
333
echo %0 %*
334
set "s10=$t=1;$toggle='38'; if((Get-MpPreference).DisableRealtimeMonitoring){$t=0;$toggle='39';}"
335
set "s11=Set-MpPreference -DisableRealtimeMonitoring $t"
336
set "s12=Set-MpPreference -DisableBehaviorMonitoring $t"
337
set "s13=Set-MpPreference -DisableIOAVProtection $t"
338
set "s14=write-host $toggle"
339
for /f "delims=" %%a in ('call powershell.exe -c "%s10%;%s11%;%s12%;%s13%;%s14%;"') do set "toggle=%%a"
340
reg add "%menu%\84Defender" /v Icon /d "ieframe.dll,%toggle%" /f %.%
341
exit/b
342
343
:update_defender - triggered from WScript to get definitions from MMPC, regardless of updates being blocked
344
tasklist /FI "IMAGENAME eq MpCmdRun.exe" | find ".exe" %.%
345
if not errorlevel 1 exit/b
346
pushd %ProgramFiles%\Windows Defender
347
call MpCmdRun.exe -removedefinitions -dynamicsignatures
348
call MpCmdRun.exe -SignatureUpdate -MMPC
349
exit/b
350
351
:setup
352
echo %0 %*
353
pushd %SystemRoot%
354
if /i "%~f0"=="%f0%" (set "initial_setup=") else copy /y "%~f0" "%f0%" %.%
355
:: Create WUTUndo for emergencies
356
 >WUTUndo.bat echo/pushd %%~dp0system32\config
357
>>WUTUndo.bat echo/reg load HKLM\WUTUndo1 SOFTWARE
358
>>WUTUndo.bat echo/set "koff=HKLM\WUTUndo1\Microsoft\Windows NT\CurrentVersion\Image File Execution Options" ^&set "kon=%ifeo%"
359
>>WUTUndo.bat echo/for %%%%B in (%exe%) do for %%%%K in ("%%koff%%" "%%kon%%") do reg delete "%%%%~K\%%%%B.exe" /f 2^>nul
360
>>WUTUndo.bat echo/reg unload HKLM\WUTUndo1
361
>>WUTUndo.bat echo/reg load HKLM\WUTUndo2 SYSTEM
362
>>WUTUndo.bat echo/for %%%%K in (WUTUndo2 SYSTEM) do (
363
>>WUTUndo.bat echo/ reg delete "HKLM\%%%%~K\ControlSet001\Services\TrustedInstaller" /v DependOnService /f 2^>nul
364
>>WUTUndo.bat echo/ reg delete "HKLM\%%%%~K\CurrentControlSet\Services\TrustedInstaller" /v DependOnService /f 2^>nul
365
>>WUTUndo.bat echo/)
366
>>WUTUndo.bat echo/reg unload HKLM\WUTUndo2
367
:: Create WUTRefresh to hijack update notifications and refresh context menu in addition to preventing forced reboots
368
>WUTRefresh.bat echo/@start "WUTRefresh" /min wscript.exe /e:JScript "%f0%" WUTRefresh
369
:: Create tasks to run context menu entries with proper access and no output window
370
start "WUT" wscript /e:JScript "%~f0" cmd "call `%~f0` setup_schtasks"
371
:: WUT options
372
for %%a in (NoBlock NoRefresh) do reg add "HKLM\SOFTWARE\WUT.bat" /v %%a /d "Enable" /f %.%
373
call :toggle blocking
374
exit/b
375
376
:setup_schtasks - no stalling separate process
377
set "strun=wscript.exe /e:JScript \"%f0%\" run%window%"
378
for %%t in (refresh lists upgrades installs downloads service repair report speech search defender toggle renew remove) do (
379
 schtasks /create /ru "%username%" /sc once /tn "WUT\%%t" /tr "%strun% %%t" /st "00:00:00" /it /rl highest /f %.%
380
)
381
for %%t in (hide unhide apply) do for /l %%n in (101,1,116) do (
382
 schtasks /create /ru "%username%" /sc once /tn "WUT\%%t\%%n" /tr "%strun% %%t %%n" /st "00:00:00" /it /rl highest /f %.%
383
)
384
exit/b
385
386
:renew
387
echo %0 %*
388
echo Renewing from internet - old version saved as %SystemRoot%\WUT.old
389
pushd %SystemRoot%
390
if exist WUT.new del /f /q WUT.new %.%
391
call wscript /e:JScript "%~f0" renew "https://pastebin.com/raw/gNsLEWJe" "%SystemRoot%\WUT.new"
392
if exist WUT.new copy /y "%f0%" WUT.old %.% &copy /y WUT.new "%f0%" %.% &del /f /q WUT.new %.%
393
start "WUT" "%f0%" %.%
394
exit
395
396
:remove
397
echo %0 %*
398
for %%a in (NoBlock NoRefresh) do reg add "HKLM\SOFTWARE\WUT.bat" /v %%a /d "Disable" /f %.%
399
call :toggle off
400
reg delete "HKLM\SOFTWARE\WUT.bat" /f %.%
401
for %%a in ("" "0pending" "1hide" "2unhide" "3apply") do reg delete "%wut%%%~a" /f %.%
402
for %%t in (refresh lists upgrades installs downloads service repair report speech search defender toggle renew remove) do (
403
 schtasks /delete /tn "WUT\%%t" /f %.%
404
)
405
for %%t in (hide unhide apply) do for /l %%n in (101,1,116) do schtasks /delete /tn "WUT\%%t\%%n" /f %.%
406
for %%t in (hide unhide apply) do schtasks /delete /tn "WUT\%%t" /f %.%
407
schtasks /delete /tn "WUT" /f %.%
408
sc config wuauserv type= share depend= rpcss %.%
409
sc config TrustedInstaller type= own depend= / %.%
410
pushd %SystemRoot%
411
del /f /q WUT.bat WUT.old DefenderManualUpdate.bat WUTRefresh.bat WUTUndo.bat "%f0%" %.%
412
exit/b
413
414
:reg_query %1:KeyName %2:ValueName %3:OutputVariable %4:other_options[example: "/t REG_DWORD"]
415
setlocal & for /f "skip=2 delims=" %%s in ('reg query "%~1" /v "%~2" /z 2^>nul') do set "rq=%%s" & call set "rv=%%rq:*)    =%%"
416
endlocal & set "%~3=%rv%" & exit/b &rem                                         AveYo: call :reg_query "HKCU\MyKey" "MyValue" MyVar
417
418
::---------------------------------------------------------------------------------------------------------------------------------
419
:JScript_functions                                                                 AveYo: Switch syntax highlighter to 'javascript'
420
::-------------------------------------------------------------------------------------------------------------------------------*/
421
f0=WSH.ScriptFullName; run=WSH.Arguments(0); args=''; for(i=1;i<WSH.Arguments.length;i++) args+=' "'+WSH.Arguments(i)+'"';
422
function sex(exe,args){WSH.CreateObject('Shell.Application').ShellExecute(exe,args,'','',0);}; function reg(s){ sex('reg.exe',s); }
423
424
// Open external commands in new hidden cmd instance - backquotes replaced to quotes
425
if (run=='cmd') sex('cmd','/c '+args.replace(/`/g,'"'));
426
427
// Context menu entries trigger - elevated with no popups
428
if (run=='schtasks') sex('SCHTASKS.EXE','/Run /TN '+args);
429
430
// Shift to CMD if loaded by WScript - pass arguments, prevent loop, run as admin at setup, hide window at context-menu
431
function cmd(adm,win){WSH.CreateObject('Shell.Application').ShellExecute('cmd','/c call "'+f0+'" shift "'+f0+'"'+args,'',adm,win);}
432
if (run=='run') cmd('',1); if (run=='runhide') cmd('',0); if (run=='runas') cmd('runas',1); if (run=='runashide') cmd('runas',0);
433
434
if (run=='renew') {
435
  // renew script over internet
436
  try{
437
  downloader=WSH.CreateObject("WinHttp.WinHttpRequest.5.1");
438
  if (downloader===null) downloader=WSH.CreateObject("WinHttp.WinHttpRequest");
439
  if (downloader===null) downloader=WSH.CreateObject("MSXML2.ServerXMLHTTP");
440
  if (downloader===null) downloader=WSH.CreateObject("Microsoft.XMLHTTP");
441
  downloader.Open("GET",WSH.Arguments(1),false); downloader.Send(); oASI=downloader.ResponseBody(); downloader=undefined;
442
  oASO=WSH.CreateObject("ADODB.Stream"); oASO.type=1; oASO.Mode=3; oASO.Open; oASO.Write(oASI); oASI=undefined;
443
  oASO.SaveToFile(WSH.Arguments(2)); oASO.Close();
444
  }catch(e){} // supress all errors since we're working with com objects
445
}
446
447
// WUT Hide/Unhide/Apply lists
448
if (run=='WUTRefresh' || run=='hide' || run=='unhide' || run=='apply') {
449
  SRP=GetObject("winmgmts:StdRegProv"); pending=SRP.GetStringValue(2147483650,'SOFTWARE\\WUT.bat','Pending');
450
  if (pending===0) WSH.quit(); else SRP.SetStringValue(2147483650,'SOFTWARE\\WUT.bat','Pending','yes'); // prevent instances
451
  k='HKCR\\DesktopBackground\\shell\\WUT'; hk=k+'1hide'; uk=k+'2unhide'; ik=k+'3apply'; pk=k+'0pending';// short list keys
452
  reg('delete "'+hk+'" /f');reg('delete "'+uk+'" /f');reg('delete "'+ik+'" /f'); reg('add "'+pk+'" /v MUIVerb /d "Pending.." /f');
453
  reg('add "'+pk+'" /v SubCommands /d "" /f'); reg('add "'+pk+'" /v Icon /d "ieframe.dll,11" /f');
454
  // Check for updates
455
  count=0; wuthide=[]; wutunhide=[];
456
  try{
457
  session=WSH.CreateObject("Microsoft.Update.Session"); reboot=WSH.CreateObject("Microsoft.Update.SystemInfo").RebootRequired;
458
  searcher=session.CreateUpdateSearcher();
459
  sresult=searcher.Search("IsInstalled=0"); Updatelist=sresult.Updates; count=sresult.Updates.Count;
460
  for(i=0;i<count;i++) {
461
    itemTitle=Updatelist.Item(i).Title;
462
    minsize=Updatelist.Item(i).MinDownloadSize; maxsize=Updatelist.Item(i).MaxDownloadSize; wutsize='';
463
    if (maxsize > 1073741824) wutsize=' ['+Math.round(minsize/10737418.24)/100+' - '+Math.round(maxsize/10737418.24)/100+'GB]';
464
    else if (maxsize > 1048576) wutsize=' ['+Math.round(minsize/10485.76)/100+' - '+Math.round(maxsize/10485.76)/100+'MB]';
465
    else if (maxsize > 1024) wutsize=' ['+Math.round(minsize/10.24)/100+' - '+Math.round(maxsize/10.24)/100+'KB]';
466
    else if (maxsize > 0) wutsize=' ['+(minsize)+' - '+(maxsize)+'B]';
467
    wutTitle=Updatelist.Item(i).Title + wutsize;
468
    if (run=='apply' && WSH.Arguments(1).indexOf(itemTitle) > -1) {
469
      // Add matching entry to UpdateColl
470
      UpdateColl=WSH.CreateObject("Microsoft.Update.UpdateColl"); UpdateColl.Add(Updatelist.Item(i));
471
      // Download update
472
      downloader=session.CreateUpdateDownloader(); downloader.Updates=UpdateColl; dresult=downloader.Download();
473
      if (dresult.ResultCode==2) {
474
        // Unblock apply
475
        sex('sc','config TrustedInstaller type= own depend= /');
476
        KeyPath='SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\';
477
        SRP.DeleteKey(2147483650,KeyPath+'wuauclt.exe');
478
        SRP.DeleteKey(2147483650,KeyPath+'MoUsoCoreWorker.exe');
479
        SRP.DeleteKey(2147483650,KeyPath+'sedlauncher.exe');
480
        SRP.DeleteKey(2147483650,KeyPath+'sedsvc.exe');
481
        WSH.Sleep(1000);
482
        //Apply update
483
        installer=session.CreateUpdateInstaller(); installer.Updates=UpdateColl; iresult=installer.Install();
484
        if (iresult.ResultCode==2) continue;
485
      }
486
    }
487
    // hide and unhide are very simple bool flip compared to apply
488
    if (run=='hide' && WSH.Arguments(1).indexOf(itemTitle) > -1) {
489
      Updatelist.Item(i).IsHidden=true; wutunhide.push(wutTitle); continue;
490
    }
491
    if (run=='unhide' && WSH.Arguments(1).indexOf(itemTitle) > -1) {
492
      Updatelist.Item(i).IsHidden=false; wuthide.push(wutTitle); continue;
493
    }
494
    // Trigger :update_defender to manually refresh definitions from MMPC
495
    if (Updatelist.Item(i).IsHidden===false && itemTitle.indexOf('(Definition') > -1) {
496
      sex('cmd','/c call "'+f0+'" update_defender');
497
    }
498
    // Sorting lists
499
    if (Updatelist.Item(i).IsHidden) wutunhide.push(wutTitle); else wuthide.push(wutTitle);
500
  }
501
  // Generate Hide context menu
502
  if (wuthide.length>0){
503
    reg('add "'+hk+'" /v MUIVerb /d "Hide '+"\t"+wuthide.length+'" /f');
504
    reg('add "'+hk+'" /v Icon /d "ieframe.dll,42" /f');
505
    reg('add "'+hk+'" /v SubCommands /d "" /f');
506
    for(i=101,n=wuthide.length+101;i<n;i++) {
507
      reg('add "'+hk+'\\shell\\'+i+'" /v MUIVerb /d "'+wuthide[i-101]+'" /f');
508
      reg('add "'+hk+'\\shell\\'+i+'\\command" /ve /d "wscript.exe /e:JScript \\"'+f0+'\\" schtasks WUT\\hide\\'+i+'" /f');
509
    }
510
  }
511
  // Generate Unhide context menu
512
  if (wutunhide.length>0){
513
    reg('add "'+uk+'" /v MUIVerb /d "Unhide '+"\t"+wutunhide.length+'" /f');
514
    reg('add "'+uk+'" /v Icon /d "ieframe.dll,42" /f');
515
    reg('add "'+uk+'" /v SubCommands /d "" /f');
516
    for(i=101,n=wutunhide.length+101;i<n;i++) {
517
      reg('add "'+uk+'\\shell\\'+i+'" /v MUIVerb /d "'+wutunhide[i-101]+'" /f');
518
      reg('add "'+uk+'\\shell\\'+i+'\\command" /ve /d "wscript.exe /e:JScript \\"'+f0+'\\" schtasks WUT\\unhide\\'+i+'" /f');
519
    }
520
  }
521
  // Generate Apply context menu
522
  if (wuthide.length>0){
523
    reg('add "'+ik+'" /v MUIVerb /d "Apply '+"\t"+((reboot) ? 'must reboot ' : wuthide.length)+'" /f');
524
    reg('add "'+ik+'" /v Icon /d "ieframe.dll,42" /f');
525
    reg('add "'+ik+'" /v SubCommands /d "" /f');
526
    for(i=101,n=wuthide.length+101;i<n;i++) {
527
      reg('add "'+ik+'\\shell\\'+i+'" /v MUIVerb /d "'+wuthide[i-101]+'" /f');
528
      reg('add "'+ik+'\\shell\\'+i+'\\command" /ve /d "wscript.exe /e:JScript \\"'+f0+'\\" schtasks WUT\\apply\\'+i+'" /f');
529
    }
530
  }
531
  }catch(e){} // supress all errors since we're working with com objects
532
  reg('delete "'+pk+'" /f'); SRP.DeleteValue(2147483650,'SOFTWARE\\WUT.bat','Pending'); // Remove Pending.. temporary entry
533
}
534
//
535