@echo off
setlocal enabledelayedexpansion

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative 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"

    wscript "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------

echo **************************************************************
echo ***  Batch Uninstall Realtek Bluetooth Filter Driver               
echo ***                                                            
echo ***  Please wait a moment	                  
echo=

if %PROCESSOR_ARCHITECTURE%==AMD64 (
    set BTDIR="C:\Program Files (x86)\REALTEK\Realtek Bluetooth"
)
if %PROCESSOR_ARCHITECTURE%==x86 (
    set BTDIR="C:\Program Files\REALTEK\Realtek Bluetooth"
)


set var=%BTDIR:~1,-1%

::"%var%\dpinst.exe" /Q /D /U "%var%\Rtkfilter.inf"
powershell -ExecutionPolicy Bypass -File "%~dp0script_RTL8852BE-VT_Beacon.ps1" unin 
::powershell -ExecutionPolicy Bypass -File "%~dp0script_RTL8852BE-VT_Beacon_inband.ps1" unin
::powershell -ExecutionPolicy Bypass -File "%~dp0script_RTL8852BE.ps1" unin
::powershell -ExecutionPolicy Bypass -File "%~dp0script_RTL8852CE.ps1" unin
::powershell -ExecutionPolicy Bypass -File "%~dp0script_Legacy.ps1" unin 

sc stop RtkBtManServ
sc delete RtkBtManServ

rd /q /s %BTDIR%

ping -n 3 127.0.0.1>nul
del /F %WINDIR%\RtkBtManServ.exe


echo=
echo **************************************************************
echo ***  Driver Uninstall Finished              
echo ***                                                            
echo ***  Please restart your unit after installation finished                  
echo=
