This is what I ended up doing since I did not have any more time to put on it. It works for all cases, except when a Virtual Box 64 bit is installed in a folder that is not the default one and that the batch file is called in a 32 bit environment.
set vb_path=""
for /f "tokens=1-2*" %%A in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\VirtualBox" /v InstallDir') do (
set vb_path="%%C\VBoxManage.exe"
)
IF %vb_path%=="" (
REM Virtual Box not found. Search in 32 bit virtual box from 64 bit cmd
for /f "tokens=1-2*" %%A in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Oracle\VirtualBox" /v InstallDir') do (
set vb_path="%%C\VBoxManage.exe"
)
)
IF %vb_path%=="" (
REM Still not found. Must be 32 bit env. with 64 bit Virtual Box
REM Search in default installation folders.
IF EXIST "%ProgramFiles(x86)%\Oracle\VirtualBox\VBoxManage.exe" (
set vb_path="%ProgramFiles(x86)%\Oracle\VirtualBox\VBoxManage.exe"
) ELSE (
IF EXIST "%ProgramW6432%\Oracle\VirtualBox\VBoxManage.exe" (
set vb_path="%ProgramW6432%\Oracle\VirtualBox\VBoxManage.exe"
)
)
)
IF %vb_path%=="" (
ECHO VirtualBox folder not found in registry or default installation path!
EXIT /b 1
)