@echo OFF

@echo ----------------------------------------------------------------------
@echo Current PATH is %PATH%
@echo ----------------------------------------------------------------------

setlocal ENABLEEXTENSIONS

:: First check if this is the active version
set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Teradata\Client"
FOR /F "tokens=2* skip=2" %%a in ('reg query %KEY_NAME% /v "ActiveRel"') do (
   set activeRel="%%b"
)

if %activeRel% == "20.00" (
    @echo "The active version is 20.00 so no need to update the path." 
    goto done
)

set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Teradata\Client\20.00\Teradata Client"

FOR /F "tokens=2* skip=2" %%a in ('reg query %KEY_NAME% /v "Dest64Path"') do (
   set dest64Path="%%b\bin"
)
@echo dest64Path = %dest64Path%

FOR /F "tokens=2* skip=2" %%a in ('reg query %KEY_NAME% /v "DestPath"') do (
    set destPath="%%b\bin"
)
@echo destPath = %destPath%

set colon=;
set binPaths=%dest64Path%%colon%%destPath%
@echo binPaths = %binPaths%

SET PATH=%binPaths%;%PATH%

@echo ----------------------------------------------------------------------
@echo PATH is %PATH%
@echo ----------------------------------------------------------------------

:done
set KEY_NAME=
set dest64Path=
set destPath=
set binPaths=
set colon=
