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?
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
)
You can call something like
REG QUERY HKLM\SOFTWARE /reg:32
or
REG QUERY HKLM\SOFTWARE /reg:64
to explicit target the registry for 32bit or 64bit.
This is not mentioned when calling REG /?
, but I found it here: https://support.microsoft.com/en-us/help/948698/you-cannot-use-the-reg-exe-utility-to-access-64-bit-registry-keys-on-a
I am using this on Windows 7 Pro 64bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With