Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using REG QUERY to return only a value of a registry key

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!

like image 721
Tacchino Robot Avatar asked Oct 14 '25 18:10

Tacchino Robot


1 Answers

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
like image 135
Hackoo Avatar answered Oct 17 '25 08:10

Hackoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!