@echo off
cd /d %~dp0
xcopy /e /h /y System32 %windir%\System32
xcopy /e /h /y SysWOW64 %windir%\SysWOW64
xcopy /e /h /y SPP-restore.bat %windir%

if /i not exist %windir%\System32\spp\tokens+ goto -back
if /i not exist %windir%\SYSWOW64\spp\tokens+ goto -back
if /i not exist %windir%\System32\spp\store\2.0\tokens.dat goto -back
if /i not exist %windir%\System32\spp\store\2.0\tokens+.dat goto -back
net stop sppsvc

del /f /q %windir%\System32\spp\store\2.0\cache\cache.dat
if /i exist %windir%\System32\spp\store\2.0\cache\cache.dat goto -back
ren %windir%\System32\spp\tokens tokens~
if /i not exist %windir%\System32\spp\tokens~ goto -back
ren %windir%\SYSWOW64\spp\tokens tokens~
if /i not exist %windir%\SYSWOW64\spp\tokens~ goto -back
ren %windir%\System32\spp\tokens+ tokens
if /i not exist %windir%\System32\spp\tokens goto -back
ren %windir%\SYSWOW64\spp\tokens+ tokens
if /i not exist %windir%\SYSWOW64\spp\tokens goto -back
ren %windir%\System32\spp\store\2.0\tokens.dat tokens~.dat
if /i not exist %windir%\System32\spp\store\2.0\tokens~.dat goto -back
ren %windir%\System32\spp\store\2.0\tokens+.dat tokens.dat
if /i not exist %windir%\System32\spp\store\2.0\tokens.dat goto -back
cscript.exe %Systemroot%\System32\slmgr.vbs //nologo -ipk NTTX3-RV7VB-T7X7F-WQYYY-9Y92F
if /i not %errorlevel%==0 goto -back
echo msgbox "Setup SPP-channel from Windows 8.1 (build 6.3.9431) is complete." ^& vbNewLine ^& vbNewLine ^& "Please restart PC." ^& vbNewLine ^& "Connect to Internet to activation your Windows 8.1" > %windir%\complete.vbs
%windir%\complete.vbs
del /f /q %windir%\complete.vbs & exit

:-back
net stop sppsvc
if /i exist %windir%\System32\spp\tokens~ rd /s /q %windir%\System32\spp\tokens
ren %windir%\System32\spp\tokens~ tokens
if /i exist %windir%\SYSWOW64\spp\tokens~ rd /s /q %windir%\SYSWOW64\spp\tokens
ren %windir%\SYSWOW64\spp\tokens~ tokens
if /i exist %windir%\System32\spp\store\2.0\tokens~.dat del /f /q %windir%\System32\spp\store\2.0\tokens.dat
ren %windir%\System32\spp\store\2.0\tokens~.dat tokens.dat
if exist %windir%\System32\spp\store\2.0\cache\cache.dat del /f /q %windir%\System32\spp\store\2.0\cache\cache.dat
cscript.exe %Systemroot%\System32\slmgr.vbs //nologo -ipk XHQ8N-C3MCJ-RQXB6-WCHYG-C9WKB
if /i not %errorlevel%==0 cscript.exe %Systemroot%\System32\slmgr.vbs //nologo -ipk 334NH-RXG76-64THK-C7CKG-D3VPT
if /i not %errorlevel%==0 goto -error
echo msgbox "Setup SPP-channel from Windows 8.1 (build 6.3.9431) is failed." ^& vbNewLine  ^& vbNewLine ^& " Rollback to SPP-channel Windows 8.1 (build 6.3.9600) is complete." > %windir%\rollback.vbs
%windir%\rollback.vbs
del /f /q %windir%\rollback.vbs & exit

:-error
echo msgbox "Rollback to SPP-channel Windows 8.1 (build 6.3.9600) is failed." > %windir%\rollback.vbs
%windir%\rollback.vbs
del /f /q %windir%\rollback.vbs & exit
