@setlocal DisableDelayedExpansion
@echo off
if defined PROCESSOR_ARCHITEW6432 start "" %SystemRoot%\Sysnative\cmd.exe /c "%0 " &exit
set "SysPath=%SystemRoot%\System32"
set "Path=%SysPath%;%SystemRoot%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\"

set "_err===== ERROR ===="
for /f "tokens=6 delims=[]. " %%# in ('ver') do if %%# geq 7600 goto :E_Win
reg query HKU\S-1-5-19 1>nul 2>nul || goto :E_Admin

set "_EDT=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
set "_SVC=HKLM\SYSTEM\CurrentControlSet\Services\wuauserv\Parameters"
set "xOS=64"
set "xBT=amd64"
if /i %PROCESSOR_ARCHITECTURE%==x86 (if not defined PROCESSOR_ARCHITEW6432 (
  set "xOS=32"
  set "xBT=x86"
  )
)
set "_bat=%~f0"
set "_arg=%~1"
set "_elv="
if defined _arg if /i "%_arg%"=="-su" set _elv=1

set "_work=%~dp0"
set "_work=%_work:~0,-1%"
setlocal EnableDelayedExpansion
pushd "!_work!"

:Begin
set "PKGS=%SystemRoot%\Servicing\Packages"
if exist "%PKGS%\Microsoft-Windows-Foundation-Package*6.0.6001.18000.mum" goto :E_Win

if not exist "%PKGS%\Package_25_for_KB4474419*.mum" if not exist "%SysPath%\kerneles.dll" (
echo %_err%
echo Neither WUC Package or Patcher are installed.
goto :TheEnd
)

@cls
echo.
choice /C YN /N /M "WUC 7.7.6003.20555 will be unintalled. Continue? [y/n]: "
if errorlevel 2 exit

call :StopService wuauserv 1>nul 2>nul
if not exist "%SysPath%\kerneles.dll" goto :proceed

echo.
echo ____________________________________________________________
echo.
echo Removing Patched wuaueng.dll . . .
echo.

if exist "%SysPath%\kerneles.dll" del /f /q %SysPath%\kerneles.dll
if exist "%SysPath%\wuaueng6.dll" del /f /q %SysPath%\wuaueng6.dll
if exist "%SysPath%\sle.dll" del /f /q "%SysPath%\sle.dll"
1>nul 2>nul reg add "%_SVC%" /f /v ServiceDll /t REG_EXPAND_SZ /d ^%%SystemRoot^%%\System32\wuaueng.dll

set "_ebak="
reg query "%_EDT%" /v EditionID_bak 1>nul 2>nul && for /f "skip=2 tokens=2*" %%a in ('reg query "%_EDT%" /v EditionID_bak 2^>nul') do set "_ebak=%%b"
if defined _ebak (
1>nul 2>nul reg add "%_EDT%" /f /v EditionID /d %_ebak%
1>nul 2>nul reg delete "%_EDT%" /f /v EditionID_bak
)

if not exist "%PKGS%\Package_25_for_KB4474419*.mum" (
echo.
echo Done.
goto :TheEnd
)

:proceed
echo.
echo ____________________________________________________________
echo.
echo Uninstalling Windows Update Client . . .
echo.

if exist "%PKGS%\Package_25_for_KB4474419~31bf3856ad364e35~%xBT%~~6.0.4.0.mum" (
start /w PkgMgr.exe /up:"Package_25_for_KB4474419~31bf3856ad364e35~%xBT%~~6.0.4.0" /quiet /norestart 1>nul 2>nul
)
for /L %%# in (2,1,19) do if exist "%PKGS%\Package_%%#_for_KB4474419~31bf3856ad364e35~%xBT%~~6.0.4.0.mum" (
start /w PkgMgr.exe /up:"Package_%%#_for_KB4474419~31bf3856ad364e35~%xBT%~~6.0.4.0" /quiet /norestart 1>nul 2>nul
)

echo.
echo ____________________________________________________________
echo.
echo Done.
if exist "%SystemRoot%\WinSxS\pending.xml" (
echo System restart is required to complete the process.
)
goto :TheEnd

:StopService
sc query %1 | find /i "STOPPED" || net stop %1 /y
sc query %1 | find /i "STOPPED" || sc stop %1
exit /b

:E_Admin
echo %_err%
echo This script requires administrator privileges.
goto :TheEnd

:E_Win
echo %_err%
echo This project is for Windows Vista only.
goto :TheEnd

:TheEnd
echo.
echo Press any key to exit.
pause >nul
goto :eof
