Skip to content

Instantly share code, notes, and snippets.

@espanafly
Last active December 29, 2021 12:22
Show Gist options
  • Select an option

  • Save espanafly/3041ce74cd2493d349e58c31630f98e5 to your computer and use it in GitHub Desktop.

Select an option

Save espanafly/3041ce74cd2493d349e58c31630f98e5 to your computer and use it in GitHub Desktop.
Block or Allow Windows and Store updates. Toggle On-Off Windows and Store updates
@ECHO OFF
CHCP 437 >NUL
COLOR 1F
:: Source: https://docs.microsoft.com/en-us/windows/privacy/manage-connections-from-windows-operating-system-components-to-microsoft-services#29-windows-update
TITLE Windows ^& Store Update Toggle On-Off
:: Run as administrator AveYo: no ps\vbs so no av delay, proper parameters pass, loop guard -- Source: https://is.gd/3c6hSR
set "S=%systemroot%\system32"& set "A=%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\WinX\Group3\01 - Command Prompt"
>nul fltmc || ( if +%+% neq +A if exist "%A%.lnk" ( start "" /high "%A%.lnk" /x/d/rset+=A^&cmd /rcall "%~f0" %*&&exit/b0) else (
>nul reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%tmp%\cmd.exe" /f /d RUNASADMIN
>nul robocopy /lev:0 "%S%/" "%tmp%/" cmd.exe& start "" /high "%tmp%\cmd.exe" /x/d/rset+=A^&"%comspec%" /rcall "%~f0" %*&&exit/b0))
CLS
echo.
echo.
CHOICE /C:BA /N /M "Do you want to [B]lock or [A]llow Windows ^& Store updates? ['b'lock /'a'llow] : "
IF %ERRORLEVEL% EQU 2 (
GOTO :Allow_WU
)
CLS
REG QUERY "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v "DoNotConnectToWindowsUpdateInternetLocations" | find "1" >Nul
if %errorlevel%==0 (
:: Execute only if necessary
CLS
ECHO Windows ^& Store Update is already blocked
explorer.exe /e, ms-settings:windowsupdate-history
timeout /t 2 /nobreak >nul
explorer.exe /e, ms-settings:windowsupdate
ECHO:
ECHO The Windows Update Control Panel shows:
ECHO:
ECHO "*Some settings are managed by your organization"
GOTO :QUIT
)
CLS
REG ADD "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v "DoNotConnectToWindowsUpdateInternetLocations" /t "REG_DWORD" /d "1" /f >NUL
REG ADD "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v "DisableWindowsUpdateAccess" /t "REG_DWORD" /d "1" /f >NUL
REG ADD "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v "WUServer" /t REG_SZ /d " " /f >NUL
REG ADD "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v "WUStatusServer" /t REG_SZ /d " " /f >NUL
REG ADD "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v "UpdateServiceUrlAlternate" /t REG_SZ /d " " /f >NUL
REG ADD "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "UseWUServer" /t "REG_DWORD" /d "1" /f >NUL
ECHO Blocking Windows ^& Store Update
explorer.exe /e, ms-settings:windowsupdate-history
timeout /t 2 /nobreak >nul
explorer.exe /e, ms-settings:windowsupdate
ECHO:
ECHO The Windows Update Control Panel shows:
ECHO:
ECHO "*Some settings are managed by your organization"
GOTO :QUIT
::---------------------
:Allow_WU
CLS
REG QUERY HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate | find "1" >Nul
if %errorlevel%==1 (
CLS
:: Execute only if necessary
ECHO Windows ^& Store Update is already allowed
explorer.exe /e, ms-settings:windowsupdate-history
timeout /t 2 /nobreak >nul
explorer.exe /e, ms-settings:windowsupdate
GOTO :QUIT
)
ECHO Allowing Windows ^& Store Update
REG DELETE HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate /f >NUL
explorer.exe /e, ms-settings:windowsupdate-history
timeout /t 2 /nobreak >nul
explorer.exe /e, ms-settings:windowsupdate
:QUIT
ECHO:
::ECHO Done
ECHO:
PAUSE
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment