:: Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/

@echo off
:Menu
cls
echo ======================================================================
echo WARNING: This script will rebuild the WMI Repository.
echo It is provided "AS IS" without support or responsibility for damages.
echo.
echo It is HIGHLY RECOMMENDED to create a System Restore Point before 
echo proceeding.
echo ======================================================================
set /p userinput="Do you want to proceed? (Y/N): "

:: Handle user input and jump to logic
if /I "%userinput%"=="Y" goto StartRepair
if /I "%userinput%"=="N" exit
goto Menu

:StartRepair
@echo on 
cd /d c:\temp 
if not exist %windir%\system32\wbem goto TryInstall 
cd /d %windir%\system32\wbem 
net stop winmgmt 
winmgmt /kill 
if exist Rep_bak rd Rep_bak /s /q 
rename Repository Rep_bak 
for %%i in (*.dll) do RegSvr32 -s %%i 
for %%i in (*.exe) do call :FixSrv %%i 
for %%i in (*.mof,*.mfl) do Mofcomp %%i 
net start winmgmt 
goto Completion

:FixSrv 
if /I (%1) == (wbemcntl.exe) goto SkipSrv 
if /I (%1) == (wbemtest.exe) goto SkipSrv 
if /I (%1) == (mofcomp.exe) goto SkipSrv 
%1 /Regserver 
:SkipSrv 
goto :eof

:TryInstall 
if not exist wmicore.exe goto Completion
wmicore /s 
net start winmgmt 

:Completion
@echo off
echo.
echo ======================================================================
echo WMI Repair Complete.
echo PLEASE RESTART THE MEDIASERVER APPLICATION NOW.
echo ======================================================================
echo Press any key to finish the script.
pause > nul
exit