@echo off
setlocal enabledelayedexpansion

set dir=%~dp0

set interfaceName=""
for /f "tokens=2 delims==" %%F in ('wmic nic where "NetConnectionID='TAP-HT Portal'" get NetConnectionID /format:list') do set interfaceName=%%F

if "%interfaceName%" == "TAP-HT Portal" (
	echo Updating TAP
	"%dir%tapinstall.exe" update "%dir%OemVista.inf" tap0901
) else (
	echo Installing new TAP
	"%dir%tapinstall.exe" install "%dir%OemVista.inf" tap0901
)

set interfaceId=""
for /f "tokens=2 delims==" %%F in ('wmic nic where "ServiceName='tap0901'" get ServiceName /format:list') do set interfaceId=%%F

if not "%interfaceId%" == "tap0901" (
	goto :error
)

set interfaceName=""
for /f "tokens=2 delims==" %%F in ('wmic nic where "ServiceName='tap0901'" get NetConnectionID /format:list') do set interfaceName=%%F

netsh interface set interface name="%interfaceName%" newname="TAP-HT Portal"
goto :end

:error
echo WScript.Quit MsgBox("Error installing TAP Driver, Application may not work correctly", VbCritical, "Error during installation") > #.vbs
cscript //nologo #.vbs
del #.vbs
goto :end

:end
