@echo off
set "b=0"
cls
TITLE Checking for Admin...
echo.
cd %systemroot%\system32
call :IsAdmin

:StartScript
cls

ver | findstr /i " 10\.0\." > nul
IF "%ERRORLEVEL%" EQU "0" goto :Win10_OK
echo This script only works on Windows 10 Kernels.
echo.
pause
exit

:Win10_OK
echo Reset WU etc to defaults...
TITLE Reset WU, BITS etc to defaults... Please Wait...
COLOR 1F

:bits
set /a "b=%b%+1"
if "%b%" equ "3" goto :Start
net stop bits >NUL 2>&1
sc query bits | findstr /I /C:"STOPPED" >NUL 2>&1
if not "%errorlevel%"=="0" goto :bits

set "w=0"

:wuauserv
set /a "w=%w%+1"
if "%w%" equ "3" goto :Start
net stop wuauserv >NUL 2>&1
sc query wuauserv | findstr /I /C:"STOPPED" >NUL 2>&1
if not "%errorlevel%"=="0" goto :wuauserv

set "app=0"

:appidsvc
set /a "app=%app%+1"
if "%app%" equ "3" goto :Start
net stop appidsvc >NUL 2>&1
sc query appidsvc | findstr /I /C:"STOPPED" >NUL 2>&1
if not "%errorlevel%"=="0" goto :appidsvc

set "c=0"

:cryptsvc
set /a "c=%c%+1"
if "%c%" equ "3" goto :Start
net stop cryptsvc >NUL 2>&1
sc query cryptsvc | findstr /I /C:"STOPPED" >NUL 2>&1
if not "%errorlevel%"=="0" goto :cryptsvc

:ResetDNS
echo Reset DNS caches etc...
Ipconfig /flushdns >NUL 2>&1
del /s /q /f "%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat"
del /s /q /f "%ALLUSERSPROFILE%\Microsoft\Network\Downloader\qmgr*.dat"
del /s /q /f "%SYSTEMROOT%\Logs\WindowsUpdate\*"

if exist "%SYSTEMROOT%\winsxs\pending.xml.bak" del /s /q /f "%SYSTEMROOT%\winsxs\pending.xml.bak"
if exist "%SYSTEMROOT%\winsxs\pending.xml" (
    takeown /f "%SYSTEMROOT%\winsxs\pending.xml"
    attrib -r -s -h /s /d "%SYSTEMROOT%\winsxs\pending.xml"
    ren "%SYSTEMROOT%\winsxs\pending.xml" "pending.xml.bak"
)

if exist "%SYSTEMROOT%\SoftwareDistribution.bak" rmdir /s /q "%SYSTEMROOT%\SoftwareDistribution.bak"
if exist "%SYSTEMROOT%\SoftwareDistribution" (
    attrib -r -s -h /s /d "%SYSTEMROOT%\SoftwareDistribution"
    ren "%SYSTEMROOT%\SoftwareDistribution" "SoftwareDistribution.bak"
)

if exist "%SYSTEMROOT%\system32\Catroot2.bak" rmdir /s /q "%SYSTEMROOT%\system32\Catroot2.bak"
if exist "%SYSTEMROOT%\system32\Catroot2" (
    attrib -r -s -h /s /d "%SYSTEMROOT%\system32\Catroot2"
    ren "%SYSTEMROOT%\system32\Catroot2" "Catroot2.bak"
)

echo Reset Windows Update policies...
reg delete "HKCU\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /f >NUL 2>&1
reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\WindowsUpdate" /f >NUL 2>&1
reg delete "HKCU\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /f >NUL 2>&1

reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /f >NUL 2>&1
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\WindowsUpdate" /f >NUL 2>&1
reg delete "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /f >NUL 2>&1

reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy\PolicyState" /v "DeferFeatureUpdates" /t REG_DWORD /d "0" /f >NUL 2>&1
reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy\PolicyState" /v "DeferQualityUpdates" /t REG_DWORD /d "0" /f >NUL 2>&1
reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy\PolicyState" /v "IsDeferrallsActive" /t REG_DWORD /d "1" /f >NUL 2>&1
reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy\Settings" /v "PausedFeatureStatus" /t REG_DWORD /d "0" /f >NUL 2>&1
reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UpdatePolicy\Settings" /v "PausedQualityStatus" /t REG_DWORD /d "0" /f >NUL 2>&1
reg delete "HKLM\SOFTWARE\Policies\Microsoft\WindowsStore" /v "DisableOSUpgrade" /f >NUL 2>&1
reg delete "HKLM\SYSTEM\Setup\UpgradeNotification" /v "UpgradeAvailable" /f >NUL 2>&1

gpupdate /force >NUL 2>&1

echo Reset the BITS service and the Windows Update service to the default security descriptors...
sc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)

sc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)

echo Re-registering the BITS and the Windows Update dll files...
cd /d "%windir%\system32"
regsvr32.exe /s atl.dll >NUL 2>&1
regsvr32.exe /s urlmon.dll >NUL 2>&1
regsvr32.exe /s mshtml.dll >NUL 2>&1
regsvr32.exe /s shdocvw.dll >NUL 2>&1
regsvr32.exe /s browseui.dll >NUL 2>&1
regsvr32.exe /s jscript.dll >NUL 2>&1
regsvr32.exe /s vbscript.dll >NUL 2>&1
regsvr32.exe /s scrrun.dll >NUL 2>&1
regsvr32.exe /s msxml.dll >NUL 2>&1
regsvr32.exe /s msxml3.dll >NUL 2>&1
regsvr32.exe /s msxml6.dll >NUL 2>&1
regsvr32.exe /s actxprxy.dll >NUL 2>&1
regsvr32.exe /s softpub.dll >NUL 2>&1
regsvr32.exe /s wintrust.dll >NUL 2>&1
regsvr32.exe /s dssenh.dll >NUL 2>&1
regsvr32.exe /s rsaenh.dll >NUL 2>&1
regsvr32.exe /s gpkcsp.dll >NUL 2>&1
regsvr32.exe /s sccbase.dll >NUL 2>&1
regsvr32.exe /s slbcsp.dll >NUL 2>&1
regsvr32.exe /s cryptdlg.dll >NUL 2>&1
regsvr32.exe /s oleaut32.dll >NUL 2>&1
regsvr32.exe /s ole32.dll >NUL 2>&1
regsvr32.exe /s shell32.dll >NUL 2>&1
regsvr32.exe /s initpki.dll >NUL 2>&1
regsvr32.exe /s wuapi.dll >NUL 2>&1
regsvr32.exe /s wuaueng.dll >NUL 2>&1
regsvr32.exe /s wuaueng1.dll >NUL 2>&1
regsvr32.exe /s wucltui.dll >NUL 2>&1
regsvr32.exe /s wups.dll >NUL 2>&1
regsvr32.exe /s wups2.dll >NUL 2>&1
regsvr32.exe /s wuweb.dll >NUL 2>&1
regsvr32.exe /s qmgr.dll >NUL 2>&1
regsvr32.exe /s qmgrprxy.dll >NUL 2>&1
regsvr32.exe /s wucltux.dll >NUL 2>&1
regsvr32.exe /s muweb.dll >NUL 2>&1
regsvr32.exe /s wuwebv.dll >NUL 2>&1
regsvr32.exe /s wudriver.dll >NUL 2>&1
netsh winsock reset >NUL 2>&1
netsh winsock reset proxy >NUL 2>&1

echo Settin services startup type as automatic..
sc config wuauserv start= auto >NUL 2>&1
sc config bits start= auto >NUL 2>&1
sc config DcomLaunch start= auto >NUL 2>&1

:Start
echo Restarting bits, wuaserv etc...
net start bits
net start wuauserv
net start appidsvc
net start cryptsvc

echo.
echo Done.  Reboot required.
echo.
pause
exit

=====================================================================================
:IsAdmin
Reg query "HKU\S-1-5-19\Environment"
If Not %ERRORLEVEL% EQU 0 (
 Cls
 echo.
 Echo You must have administrator rights to continue ...
 echo.
 Pause
 Exit
)

Cls

exit /b

