@ECHO OFF
SETLOCAL

:: Check if the script is running as administrator
NET SESSION >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
    ECHO This script requires administrative privileges. Please run as Administrator.
    ECHO Requesting elevation...
    PowerShell -Command "Start-Process '%~0' -Verb RunAs"
    EXIT /B
)

:: Stop and delete the service
echo Stopping the MIBService...
net stop MIBService


echo Deleting the MIBService...
sc delete MIBService

:: Set .NET framework path (for .NET 4.0)
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%

InstallUtil /i "%~dp0MIBService.exe"


net start MIBService

echo ---------------------------------------------------
echo Done!

:: Prevent the window from closing automatically
ENDLOCAL
EXIT