REM Load likely VBoxManage location from configuration file
CALL "%~dp0\CONFIG.BAT"

IF EXIST "%VBM%" GOTO vbm_found

REM Before searching, try a likely alternative

SET VBM=d:\Program Files\Oracle\VirtualBox\VBoxManage.exe

IF EXIST "%VBM%" GOTO vbm_found

ECHO.
ECHO %time% Searching %SystemDrive% for VBoxManage, this may take a while
ECHO.
ECHO To skip the search process and speed up script execution, edit
ECHO config.bat so that VBM contains the full path to VBoxManage.exe.
ECHO.

FOR /r %SystemDrive%\ %%a IN (*) DO (
    IF "%%~nxa"=="VBoxManage.exe" SET VBM=%%~dpnxa && GOTO vbm_found
)

ECHO.
ECHO %time% Cannot find VBoxManage.exe (part of VirtualBox) on %SystemDrive%.

ECHO.
ECHO %time% Searching D: for VBoxManage, this may take a while
ECHO.

FOR /r D:\ %%a IN (*) DO (
    IF "%%~nxa"=="VBoxManage.exe" SET VBM=%%~dpnxa && GOTO vbm_found
)

ECHO.
ECHO %time% Cannot find VBoxManage.exe (part of VirtualBox) on D:.
ECHO %time% Giving up. Program stops.
ECHO.
GOTO :terminate

:vbm_found
ECHO VBoxManage.exe found:
ECHO "%VBM%"
ECHO Version:
"%VBM%" --version

REM vim: set ai ts=4 sw=4 et ft=dosbatch:

