@echo off

REM ----------------------------------------------
REM Check admin rights for further script actions.
REM ----------------------------------------------

%systemroot%\System32\net.exe FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto SELECTION ) else ( goto SHOWADMINMESSAGE )

REM ----------------------------------------------

:SELECTION
cd /d %~dp0
CLS
echo FLEXID USB DRIVER OPTIONS
echo ===================================
echo.
echo 1) Install FlexID 9 (green)
echo 2) Install FlexID 10 (blue)
echo 3) Just copy FlexID 9 helper DLL's
echo 4) Exit
echo.
echo ===================================
set /p op=Type option: 
if "%op%"=="1" goto FLEXID9
if "%op%"=="2" goto FLEXID10
if "%op%"=="3" goto COPYDLLS
if "%op%"=="4" goto EXIT
echo Please Pick an option:
goto SELECTION

:FLEXID9
echo.
echo Installing FlexID 9 drivers ...
cd flexid9
haspdinst -i -kp -fss -fi
cd ..
goto COPYDLLS

:COPYDLLS
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && GOTO FLEX9_32BIT || GOTO FLEX9_64BIT

:FLEX9_32BIT
echo.
echo Copying 32-bit helper DLL's ...
cd flexid9
xcopy haspsrm_win32.dll %systemroot%\System32 /D /Q /Y
cd ..
goto ENDDRIVER

:FLEX9_64BIT
echo.
echo Copying 64-bit helper DLL's ...
cd flexid9
xcopy haspsrm_win32.dll %systemroot%\SysWOW64 /D /Q /Y
xcopy haspsrm_win64.dll %systemroot%\System32 /D /Q /Y
cd ..
goto ENDDRIVER

:FLEXID10
echo.
echo Installing FlexID 10 drivers ...
cd flexid10
setup
cd ..
goto ENDDRIVER

:SHOWADMINMESSAGE 
echo Warning: This script requires administrative rights to execute.
echo.
echo Right-click the bat-file and select "Run as administrator", or
echo start the bat-file from an administrator elevated command shell.
echo.
goto EXIT

:ENDDRIVER
echo.
echo Drivers installed - insert the USB dongle now
goto EXIT

:EXIT
pause