Skip to content

Instantly share code, notes, and snippets.

@linusgke
Created August 7, 2022 13:49
Show Gist options
  • Save linusgke/f280b4c06fa9838c41e6c68aa0753432 to your computer and use it in GitHub Desktop.
Save linusgke/f280b4c06fa9838c41e6c68aa0753432 to your computer and use it in GitHub Desktop.
DKS disable windows update service
@echo off
REM
REM MUST BE RUN AS ADMINISTRATOR
REM
%~d0
cd %~p0
set _SCRIPTLOG=DksWindowsUpdate.log
set DKS_REG_KEY=HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
set DKS_BAK_FILE=%~dp0Reg_WindowsUpdate.txt
call :Log "---- Start Disable Windows Update"
call :Log "Disable Recovery"
bcdedit.exe /set bootstatuspolicy IgnoreAllFailures 2>NUL
bcdedit.exe /set recoveryenabled No 2>NUL
rem disable update handling from driver
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DksCfg\Parameters" /v "IgnoreWindowsUpdate" /t REG_DWORD /d 1 /f 2>NUL
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\DKS\WindowsUpdate" /v "Disabled" /t REG_DWORD /d 1 /f 2>NUL
sc stop wuauserv 2>NUL
sc config wuauserv start= disabled 2>NUL
rem Check WSUS aktive
call :GetRegValue "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" "UseWUServer" UseWUServer
rem check UseWUServer
if [%UseWUServer%]==[0x1] goto WSUS_ACTIVE
rem check not exists
if [%UseWUServer%]==[] goto WSUS_NOT_ACTIVE
rem check deactivated
if [%UseWUServer%]==[0x0] goto WSUS_NOT_ACTIVE
rem ?? WSUS_ACTIVE
:WSUS_ACTIVE
rem get WUServer
call :GetRegValue "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" "WUServer" WUServer
rem check is local server (should be our redirection)
if [%WUServer%]==[127.0.0.1] goto WSUS_DKS_ACTIVE
rem check is no server ???
if [%WUServer%]==[] goto WSUS_DKS_ACTIVE
call :Log "WSUS Active - WUServer=%WUServer%"
call :Log "No changes on WindowsUpdate policies"
goto ENDE
:WSUS_DKS_ACTIVE
REM reactivate WSUS
call :Log "WSUS Active - LocalServer"
rem do not make backup
call :Log "delete reg key %DKS_REG_KEY%"
reg delete "%DKS_REG_KEY%" /f 2>NUL
goto WSUS_REDIR_ACTIVATE
:WSUS_NOT_ACTIVE
rem Activate WSUS redirection
call :Log "WSUS NOT Active"
rem backup reg key
reg export "%DKS_REG_KEY%" "%DKS_BAK_FILE%" /y 2>NUL
if not exist %DKS_BAK_FILE% (
call :Log "%DKS_REG_KEY% - NOT EXISTS"
) else (
call :Log "%DKS_REG_KEY% - Saved"
rem delete reg key
call :Log "delete reg key %DKS_REG_KEY%"
reg delete "%DKS_REG_KEY%" /f 2>NUL
)
:WSUS_REDIR_ACTIVATE
rem import WSUS redirection
call :Log "Activate WSUS redirection"
reg import "%~dp0DksWsusRedirect.txt" 2>NUL
goto ENDE
:ENDE
call :Log "---- End Disable Windows Update"
exit /b 0
:Log
echo [%date%-%time%] %1
echo [%date%-%time%] %1>>%_SCRIPTLOG%
exit /b 0
rem
rem %1 Key with ""
rem %2 ValName with ""
rem %3 ResultName
rem call :GetRegValue "HKEY_CURRENT_USER\Control Panel\Desktop" "Wallpaper" RetTest
:GetRegValue
for /f "tokens=2*" %%a in ('reg query %1 /v %2 2^>^&1^|find "REG_"') do @set %3=%%b
exit /b 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment