Skip to content

Instantly share code, notes, and snippets.

@linusgke
Created August 7, 2022 13:48
Show Gist options
  • Save linusgke/deb103a9637b5911886a182c0ce2860d to your computer and use it in GitHub Desktop.
Save linusgke/deb103a9637b5911886a182c0ce2860d to your computer and use it in GitHub Desktop.
DKS enable 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 Enable 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 0 /f 2>NUL
rem Check WSUS aktive
call :GetRegValue "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" "UseWUServer" UseWUServer
rem check not exists
if [%UseWUServer%]==[] goto WSUS_NOT_ACTIVE
rem check deactivated
if [%UseWUServer%]==[0x0] goto WSUS_NOT_ACTIVE
rem check activated
if [%UseWUServer%]==[0x1] goto WSUS_ACTIVE
rem ?? WSUS_NOT_ACTIVE
:WSUS_NOT_ACTIVE
rem Activate WSUS redirection
call :Log "WSUS redirection NOT Active"
call :Log "No changes on WindowsUpdate policies"
goto ENDE
: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_RESET
call :Log "WSUS active - WUServer=%WUServer%"
call :Log "No changes on WindowsUpdate policies"
goto ENDE
:WSUS_RESET
call :Log "WSUS redirection active"
rem delete current policies
call :Log "Delete redirection"
reg delete "%DKS_REG_KEY%" /f 2>NUL
rem Reset original policies
if exist "%DKS_BAK_FILE%" (
call :Log "Reset WindowsUpdate policies"
reg import "%DKS_BAK_FILE%" 2>NUL
) else (
call :Log "WindowsUpdate policies not active"
)
:ENDE
sc config wuauserv start= demand 2>NUL
ver | findstr 10.0
if "%errorlevel%"=="0" goto ENDE_2
rem winver < Windows 10 start wuauserv
sc config wuauserv start= auto 2>NUL
sc start wuauserv 2>NUL
goto ENDE_2
:ENDE_2
call :Log "---- End Enable 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