Batch file REG QUERY command searches in 32 bit registry instead of 64 bit

32bit-64bit, batch-file, inno-setup, registry

Solution

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
)

Problem

In my batch file, I am doing a simple command to get the VirtualBox install path. ``` REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\VirtualBox /v InstallDir ``` It works wonders when I execute the batch file from the command line, but no value is given if I launch that same batch file from Inno Setup. After a long while of testing, I noticed it was searching in the 32 bit section of the registry only when the batch file was launched from Inno Setup. To test that theory, I looked at a 32 bit Registry located there: ``` HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\NuGet\Repository ``` In my batch file, I enter the following command (notice that I don't specify the Wow6432Node, which should be wrong) ``` REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\NuGet\Repository\ ``` Indeed, when running the batch file from the command line, it does not find the registry key. However, when that same batch file is launched from Inno Setup, it finds \NuGet\repository just fine. The question now is. How do I get the 64 bit registry key (Virtual Box) with my batch file so that it works from both the command line and Inno Setup?

Original source