@echo off
setlocal enabledelayedexpansion

REM Check if the script has administrator privileges
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM If not has administrator privileges, re-run the script with administrator privileges
if '%errorlevel%' NEQ '0' (
    echo Requesting administrator privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"

REM Get the current script directory (full long path)
for /f "delims=" %%i in ('powershell -NoProfile -Command "(Get-Item '%~dp0').FullName"') do set "SCRIPT_DIR=%%i"
REM Remove trailing backslash for compatibility
REM if "%SCRIPT_DIR:~-1%"=="\" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"

REM Main scripts
echo Start reinstall driver...
echo Step 1: uninstall current drivers
call "%SCRIPT_DIR%\driver\uninstall.bat" 1

echo Step 2: Install new driver
call "%SCRIPT_DIR%\driver\install.bat" 1

echo Reinstall completed
pause

