@echo off
cd /d "%~dp0"
%windir%\system32\whoami.exe /USER | find /i "S-1-5-18" 1>nul || (
echo ============================================================
echo ERROR: Use the outer Uninstaller.cmd to launch the process.
echo ============================================================
echo.
echo.
echo Press any key to exit...
pause >nul
goto :eof
)
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
if not exist "%windir%\servicing\Packages\*MediaCenter*6.3.9600.16384.mum" goto :manual
echo.
echo Uninstall DISM packages...
%windir%\System32\wevtutil.exe cl "Media Center" >nul 2>&1
%windir%\System32\dism.exe /online /norestart /remove-package /packagename:Microsoft-Windows-MediaCenter-Package~31bf3856ad364e35~amd64~~6.3.9600.16384
cd /d "%~dp0"
if %winbuild% GTR 9600 (
signtool.exe catdb /g {F750E6C3-38EE-11D1-85E5-00C04FC295EE} /r Microsoft-Windows-Foundation-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat >nul 2>&1
signtool.exe catdb /g {F750E6C3-38EE-11D1-85E5-00C04FC295EE} /r Microsoft-Windows-MediaPlayback-OC-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat >nul 2>&1
signtool.exe catdb /g {F750E6C3-38EE-11D1-85E5-00C04FC295EE} /r Microsoft-Windows-MediaPlayer-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat >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
del /f /q %windir%\servicing\Packages\*6.3.9600.16384* >nul 2>&1
)
schtasks /delete /tn "\Microsoft\Windows\Media Center\mcupdate_scheduled" /f >nul 2>&1
schtasks /delete /tn "\Microsoft\Windows\Media Center\StartRecording" /f >nul 2>&1
if exist "%windir%\winsxs\pending.xml" echo.&echo System restart is required to complete.
goto :end

:manual
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)
set _assembly64=(Microsoft.MediaCenter.Mheg,mcstoredb,Microsoft.MediaCenter.iTV.Media,Microsoft.MediaCenter.Interop,Microsoft.MediaCenter.TV.Tuners.Interop,mcupdate,BDATunePIA,mcplayerinterop,Mcx2Dvcs)
set _assemblyIL=(ehiwmp,Microsoft.MediaCenter.Bml,Microsoft.MediaCenter.iTv.Hosting,mcstore,mcglidhostobj,ehiiTV,mcepg,ehshell,ehCIR,ehexthost,Microsoft.MediaCenter,Microsoft.MediaCenter.Playback,ehiVidCtl,ehiUserXp,loadmxf,ehiActivScp,Microsoft.MediaCenter.Sports,ehiExtens,ehiWUapi,Microsoft.MediaCenter.ITVVM,ehiTVMSMusic,ehiProxy,Microsoft.MediaCenter.Shell,ehiBmlDataCarousel,ehiUPnP,Microsoft.MediaCenter.UI,Microsoft.MediaCenter.iTV,ehRecObj)
echo.
echo Manual uninstall cleanup...
%windir%\System32\wevtutil.exe cl "Media Center" >nul 2>&1
for /d %%G in %_task% do (
schtasks /delete /tn "\Microsoft\Windows\Media Center\%%G" /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
set _ngen=%windir%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe
for /d %%G in %_assembly64% do (
%_ngen% uninstall "%%G, Version=6.3.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=amd64" >nul 2>&1
)
for /d %%G in %_assemblyIL% do (
%_ngen% uninstall "%%G, Version=6.3.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil" >nul 2>&1
)
set _ngen=%windir%\Microsoft.NET\Framework\v4.0.30319\ngen.exe
for /d %%G in (BDATunePIA,mcstoredb,ehexthost32) do (
%_ngen% uninstall "%%G, Version=6.3.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86" >nul 2>&1
)
for /d %%G in (ehiExtens,Microsoft.MediaCenter,Microsoft.MediaCenter.UI) do (
%_ngen% uninstall "%%G, Version=6.3.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil" >nul 2>&1
)
%windir%\system32\sc.exe query ehRecvr | find /i "RUNNING" 1>nul && net stop ehRecvr /y >nul 2>&1
%windir%\system32\sc.exe query ehSched | find /i "RUNNING" 1>nul && net stop ehSched /y >nul 2>&1
%windir%\system32\sc.exe query Mcx2Svc | find /i "RUNNING" 1>nul && net stop Mcx2Svc /y >nul 2>&1
tasklist /FI "IMAGENAME eq mcupdate.exe" | find /i "mcupdate.exe" 1>nul && taskkill /t /f /IM mcupdate.exe >nul 2>&1
tasklist /FI "IMAGENAME eq ehrecvr.exe" | find /i "ehrecvr.exe" 1>nul && taskkill /t /f /IM ehrecvr.exe >nul 2>&1
tasklist /FI "IMAGENAME eq ehsched.exe" | find /i "ehsched.exe" 1>nul && taskkill /t /f /IM ehsched.exe >nul 2>&1
tasklist /FI "IMAGENAME eq ehshell.exe" | find /i "ehshell.exe" 1>nul && taskkill /t /f /IM ehshell.exe >nul 2>&1
tasklist /FI "IMAGENAME eq ehtray.exe" | find /i "ehtray.exe" 1>nul && taskkill /t /f /IM ehtray.exe >nul 2>&1
%windir%\system32\sc.exe delete ehRecvr >nul 2>&1
%windir%\system32\sc.exe delete ehSched >nul 2>&1
%windir%\system32\sc.exe delete Mcx2Svc >nul 2>&1
%windir%\system32\reg.exe import Uninstall.reg >nul 2>&1
set /a rnd=%random%
del /f /s /q %SystemRoot%\ehome\* >nul 2>&1
if exist "%SystemRoot%\Windows\ehome\*" for /f %%G in ('dir /b %SystemRoot%\Windows\ehome') do (
move /y %SystemRoot%\Windows\ehome\%%G %SystemRoot%\Windows\WinSxS\Temp\PendingDeletes\$$Delete.%%G.%rnd% >nul 2>&1
)
rmdir /s /q %SystemRoot%\ehome >nul 2>&1
rmdir /s /q "%SystemRoot%\System32\Tasks\Microsoft\Windows\Media Center" >nul 2>&1
for /d %%G in (BDATunePIA,mcstoredb,ehexthost32) do (
rmdir /s /q %SystemRoot%\Microsoft.NET\assembly\GAC_32\%%G >nul 2>&1
)
for /d %%G in %_assembly64% do (
rmdir /s /q %SystemRoot%\Microsoft.NET\assembly\GAC_64\%%G >nul 2>&1
)
for /d %%G in %_assemblyIL% do (
rmdir /s /q %SystemRoot%\Microsoft.NET\assembly\GAC_MSIL\%%G >nul 2>&1
)
rmdir /s /q %SystemRoot%\Microsoft.NET\assembly\GAC_MSIL\Policy.6.0.ehRecObj >nul 2>&1
rmdir /s /q %SystemRoot%\Microsoft.NET\assembly\GAC_MSIL\Policy.6.0.Microsoft.MediaCenter >nul 2>&1
rmdir /s /q %SystemRoot%\Microsoft.NET\assembly\GAC_MSIL\Policy.6.0.Microsoft.MediaCenter.UI >nul 2>&1
for /d %%G in (iTVData.dll,mcmde.dll,mcsrchPH.dll,Mcx2Svc.dll,mspbda.dll,MsPbdaCoInst.dll,sysprepMCE.dll) do (
del /f /q %SystemRoot%\System32\%%G >nul 2>&1
)
del /f /q %SystemRoot%\System32\spp\tokens\ppdlic\MCLicense-ppdlic.xrm-ms >nul 2>&1
del /f /q %SystemRoot%\System32\spp\tokens\ppdlic\MediaCenter-ppdlic.xrm-ms >nul 2>&1
del /f /q %SystemRoot%\SysWOW64\iTVData.dll >nul 2>&1
del /f /q "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Accessories\Windows Media Center.lnk" >nul 2>&1
del /f /q "%SystemDrive%\Users\Public\Desktop\Windows Media Center.lnk" >nul 2>&1

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