@setlocal DisableDelayedExpansion
@echo off
cd /d "%SystemRoot%\System32"
if not exist sle.dll exit /b 1
if not exist "%~dp0bbe.exe" exit /b 1

sc query wuauserv | find /i "STOPPED" || net stop wuauserv /y
sc query wuauserv | find /i "STOPPED" || sc stop wuauserv
set _wufile=wuaueng.dll
if exist wuaueng2.dll set _wufile=wuaueng2.dll
set _Embed=0
if exist "%SystemRoot%\Servicing\Packages\WinEmb-Branding-Embedded-*.mum" set _Embed=1

if %_Embed%==0 (
"%~dp0bbe.exe" -e "s/KERNEL32/KERNELES/" -e "s/\x73\x00\x6C\x00\x63\x00\x2E\x00\x64\x00\x6C\x00\x6C\x00/\x73\x00\x6C\x00\x65\x00\x2E\x00\x64\x00\x6C\x00\x6C\x00/" -o wuaueng3.dll %_wufile%
) else (
"%~dp0bbe.exe" -e "s/\x73\x00\x6C\x00\x63\x00\x2E\x00\x64\x00\x6C\x00\x6C\x00/\x73\x00\x6C\x00\x65\x00\x2E\x00\x64\x00\x6C\x00\x6C\x00/" -o wuaueng3.dll %_wufile%
)
if not exist wuaueng3.dll exit /b 1
reg add "HKLM\SYSTEM\CurrentControlSet\services\wuauserv\Parameters" /f /v ServiceDll /t REG_EXPAND_SZ /d ^%%SystemRoot^%%\System32\wuaueng3.dll

set "_EDT=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
set "_ebak="
for /f "skip=2 tokens=2*" %%a in ('reg query "%_EDT%" /v EditionID') do set "_ebak=%%b"
reg query "%_EDT%" /v EditionID_bak 2>nul && for /f "skip=2 tokens=2*" %%a in ('reg query "%_EDT%" /v EditionID_bak') do set "_ebak=%%b"
set _eid=ServerEnterprise
reg query "%_EDT%" /v EditionID | find /i "ServerStandard" 1>nul && set _eid=ServerStandard
if exist "wbem\slw.dll" (
if defined _ebak reg add "%_EDT%" /f /v EditionID /d %_ebak%
reg delete "%_EDT%" /f /v EditionID_bak 2>nul
) else (
reg add "%_EDT%" /f /v EditionID /d %_eid%
if defined _ebak reg add "%_EDT%" /f /v EditionID_bak /d %_ebak%
)

exit /b 0
