Home > Mobile >  Using REG QUERY to return only a value of a registry key
Using REG QUERY to return only a value of a registry key

Time:07-29

I'm writing a batch file that executes certain exes in a specified folder. The fact is that the directory of these files is not always the same so I need to read the registry key to set the correct path in a variable. I'm doing this with

REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\SOMETHING" /v "Path exe"

And I get this output:

Path exe    REG_SZ    C:\Program Files (x86)\PROGRAM FOLDER

Is there any way to return only C:\Program Files (x86)\PROGRAM FOLDER without Path exe and REG_SZ?

Thanks in advance!

CodePudding user response:

Here is an example to query the Path of 7-zip :


@echo off
@FOR /f "tokens=2*" %%i in ('Reg Query "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v "Path" 2^>Nul') do Set "ExePath=%%j"
If defined ExePath (echo EXEPATH="%ExePath%" ) Else ( echo EXEPATH NOT FOUND !!!)
pause

@FOR /f "tokens=2*" %%i in ('Reg Query "HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip" /v "Path32" 2^>Nul') do Set "ExePath32=%%j"
If defined ExePath32 (echo EXEPATH32="%ExePath32%" ) Else ( echo EXEPATH32 NOT FOUND !!!)
pause
Exit /B

Another Example for VLC :


@echo off
@FOR /f "tokens=3*" %%i in ('Reg Query HKEY_LOCAL_MACHINE\SOFTWARE\VideoLAN\VLC /ve 2^>Nul') do Set "VLCPathEXE=%%j"
If defined VLCPathEXE (echo VLCPathEXE="%VLCPathEXE%") Else (echo VLCPathEXE NOT FOUND !!!)
pause
  • Related