@echo off
%windir%\system32\whoami.exe /USER | find /i "S-1-5-18" 1>nul || (
echo ============================================================
echo ERROR: Use the outer Installer.cmd to launch the process.
echo ============================================================
echo.
echo.
echo Press any key to exit...
pause >nul
goto :eof
)
set _mui=(ar-SA,bg-BG,cs-CZ,da-DK,de-DE,el-GR,en-GB,es-ES,et-EE,fi-FI,fr-FR,he-IL,hr-HR,hu-HU,it-IT,ja-JP,ko-KR,lt-LT,lv-LV,nb-NO,nl-NL,pl-PL,pt-BR,pt-PT,ro-RO,ru-RU,sk-SK,sl-SI,sr-Latn-RS,sv-SE,th-TH,tr-TR,uk-UA,zh-CN,zh-HK,zh-TW)
set _task=(ActivateWindowsSearch,ConfigureInternetTimeService,DispatchRecoveryTasks,ehDRMInit,InstallPlayReady,mcupdate,mcupdate_scheduled,MediaCenterRecoveryTask,ObjectStoreRecoveryTask,OCURActivate,OCURDiscovery,PBDADiscovery,PBDADiscoveryW1,PBDADiscoveryW2,PeriodicScanRetry,PvrRecoveryTask,PvrScheduleTask,RecordingRestart,RegisterSearch,ReindexSearchRoot,SqlLiteRecoveryTask,StartRecording,UpdateRecordPath)
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
cd /d "%~dp0"
echo.
echo Prepare...
%windir%\System32\WindowsPowerShell\v1.0\PowerShell.exe -NoLogo -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& {dir .\ | Unblock-File}"
for /d %%G in %_task% do (
schtasks /delete /tn "\Microsoft\Windows\Media Center\%%G" /f >nul 2>&1
)
rmdir /s /q "%SystemRoot%\System32\Tasks\Microsoft\Windows\Media Center" /f >nul 2>&1
%windir%\system32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Media Center" /f >nul 2>&1
for /d %%G in %_task% do (
schtasks /create /tn "\Microsoft\Windows\Media Center\%%G" /xml Tasks\%%G.xml /f >nul 2>&1
)
echo.
echo Install DISM packages...
if %winbuild% GTR 9600 (
%windir%\System32\reg.exe import dism.reg >nul 2>&1
%windir%\System32\reg.exe add HKLM\SYSTEM\CurrentControlSet\Services\ADOVMPPackage\Final /v ActivationEnabled /t REG_DWORD /d 2 /f >nul 2>&1
) else (
%windir%\System32\reg.exe import dism9600.reg >nul 2>&1
)
xcopy .\dism\* %windir%\servicing\Packages\ /chriky >nul 2>&1
%windir%\System32\dism.exe /online /norestart /add-package:MediaCenter-Package-x64-en-US.cab >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\Microsoft-Windows-MediaCenter-Package-avcore~31bf3856ad364e35~amd64~~6.3.9600.16384" /f >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\Microsoft-Windows-MediaCenter-Package~31bf3856ad364e35~amd64~~6.3.9600.16384" /f >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackageIndex\Microsoft-Windows-MediaCenter-Package-avcore~31bf3856ad364e35~amd64~~0.0.0.0" /f >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackageIndex\Microsoft-Windows-MediaCenter-Package~31bf3856ad364e35~amd64~~0.0.0.0" /f >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackageDetect\Microsoft-Windows-MediaCenter-Package-avcore~31bf3856ad364e35~amd64~~0.0.0.0" /f >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackageDetect\Microsoft-Windows-MediaCenter-Package~31bf3856ad364e35~amd64~~0.0.0.0" /f >nul 2>&1
del /f /q "%windir%\servicing\Packages\Microsoft-Windows-MediaCenter-Package*~amd64~~6.3.9600.16384*" >nul 2>&1
%windir%\System32\dism.exe /online /norestart /add-package:MediaCenter-Package-x64.cab
if %errorlevel% neq 0 goto :E_DISM
for /d %%G in %_mui% do (
if exist "%SystemRoot%\%%G\explorer.exe.mui" (
  %windir%\System32\dism.exe /online /norestart /add-package:MUI\MediaCenter-Package-x64-%%G.cab >nul 2>&1
  )
)
echo.
echo Copy patched files...
xcopy .\MediaCenter\* %SystemRoot%\ehome\ /chriky >nul 2>&1
copy /y .\MediaCenter\sys\mcmde.dll %SystemRoot%\System32 >nul 2>&1
copy /y %SystemRoot%\ehome\ehrecvr.exe %SystemRoot%\WinSxS\amd64_microsoft-windows-ehome-services-ehrecvr_31bf3856ad364e35_6.3.9600.16384_none_ae27de0ef595609d >nul 2>&1
copy /y %SystemRoot%\ehome\ehReplay.dll %SystemRoot%\WinSxS\amd64_microsoft-windows-ehome-devices-ehreplay_31bf3856ad364e35_6.3.9600.16384_none_0575d81e73a9d441 >nul 2>&1
copy /y %SystemRoot%\ehome\ehsched.exe %SystemRoot%\WinSxS\amd64_microsoft-windows-ehome-services-ehsched_31bf3856ad364e35_6.3.9600.16384_none_96315ee510051c4e >nul 2>&1
copy /y %SystemRoot%\ehome\ehtray.exe %SystemRoot%\WinSxS\amd64_microsoft-windows-ehome-ehtray_31bf3856ad364e35_6.3.9600.16384_none_1b976dca41001ea8 >nul 2>&1
copy /y %SystemRoot%\ehome\ehuihlp.dll %SystemRoot%\WinSxS\amd64_microsoft-windows-ehome-ehuihlp_31bf3856ad364e35_6.3.9600.16384_none_2cc96e8cff347d4c >nul 2>&1
copy /y %SystemRoot%\ehome\mcspad.exe %SystemRoot%\WinSxS\amd64_microsoft-windows-ehome-mcspad_31bf3856ad364e35_6.3.9600.16384_none_5255a0ef3f300f87 >nul 2>&1
copy /y %SystemRoot%\ehome\Mcx2Filter.dll %SystemRoot%\WinSxS\amd64_microsoft-windows-e..-devices-mcx2filter_31bf3856ad364e35_6.3.9600.16384_none_26cd4ad7ed6318cd >nul 2>&1
copy /y %SystemRoot%\System32\mcmde.dll %SystemRoot%\WinSxS\amd64_microsoft-windows-m..mediadeliveryengine_31bf3856ad364e35_6.3.9600.16384_none_2fe8c948337b3034 >nul 2>&1
echo.
echo Set access permissions...
if %winbuild% GTR 9600 (
signtool.exe catdb /g {F750E6C3-38EE-11D1-85E5-00C04FC295EE} "%windir%\servicing\Packages\Microsoft-Windows-Foundation-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat" >nul 2>&1
signtool.exe catdb /g {F750E6C3-38EE-11D1-85E5-00C04FC295EE} "%windir%\servicing\Packages\Microsoft-Windows-MediaPlayback-OC-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat" >nul 2>&1
signtool.exe catdb /g {F750E6C3-38EE-11D1-85E5-00C04FC295EE} "%windir%\servicing\Packages\Microsoft-Windows-MediaPlayer-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat" >nul 2>&1
)
SetACL.exe -on "HKLM\SOFTWARE\Clients\Media\Windows Media Center" -ot reg -actn restore -bckp .\AclSoft >nul 2>&1
SetACL.exe -on "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Media Center" -ot reg -actn restore -bckp .\AclSoftWow >nul 2>&1
SetACL.exe -on "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Media Center" -ot reg -actn restore -bckp .\AclSys >nul 2>&1
SetACL.exe -on "C:\Windows\System32\Tasks\Microsoft\Windows\Media Center" -ot file -actn restore -bckp .\Acl >nul 2>&1
if %winbuild% LSS 10240 goto :end
%windir%\system32\reg.exe query HKLM\SOFTWARE\Classes\Installer\Products\AAD08E5278DF5ECD02C2CC206F760320 /v ProductName 2>nul | findstr /C:"WindowsDVDPlayer" 1>nul && goto :end
echo.
echo Install DVD Player app...
windows10.0-kb3106246-x64.msi /qn >nul 2>&1

:end
echo.
echo.
echo Done.
echo.
echo Press any key to exit.
pause >nul
exit

:E_DISM
echo.
echo.
echo Installing package failed, reverting...
if exist "%windir%\servicing\Packages\*MediaCenter*~~6.3.9600.16384.mum" (
%windir%\System32\dism.exe /online /norestart /remove-package /packagename:Microsoft-Windows-MediaCenter-Package~31bf3856ad364e35~amd64~~6.3.9600.16384 >nul 2>&1
) else if exist "%windir%\servicing\Packages\*MediaCenter*en-US~6.3.9600.16384.mum" (
%windir%\System32\dism.exe /online /norestart /remove-package /packagename:Microsoft-Windows-MediaCenter-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384 >nul 2>&1
)
if %winbuild% GTR 9600 (
del /f /q %windir%\servicing\Packages\*6.3.9600.16384* >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\Microsoft-Windows-Foundation-Package~31bf3856ad364e35~amd64~~6.3.9600.16384" /f >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\Microsoft-Windows-MediaPlayback-OC-Package~31bf3856ad364e35~amd64~~6.3.9600.16384" /f >nul 2>&1
%windir%\System32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\Microsoft-Windows-MediaPlayer-Package~31bf3856ad364e35~amd64~~6.3.9600.16384" /f >nul 2>&1
)
for /d %%G in %_task% do (
schtasks /delete /tn "\Microsoft\Windows\Media Center\%%G" /f >nul 2>&1
)
rmdir /s /q "%SystemRoot%\System32\Tasks\Microsoft\Windows\Media Center" /f >nul 2>&1
%windir%\system32\reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Media Center" /f /f >nul 2>&1
echo.
echo You may reboot and try again
echo refer to C:\Windows\Logs\CBS\CBS.log to find error details
echo.
echo Press any key to exit.
pause >nul
exit