I want to output both DisplayName and DisplayVersion of each program installed.
for /f "tokens=2*" %a in (
'reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s ^
| findstr /c:"DisplayName" /c:"DisplayVersion"'
) do #echo %b
It does output both of them one per line but I want to display them on one line, how would you do that?
> DisplayName, DisplayVersion
You probably should check both 32bit and 64bit registries. If I don't specify which one, then my REG QUERY searches only 64bit by default.
Not all program keys have DisplayName and/or DisplayVersion.
The code below lists the full key if DisplayName is not present, and lists an empty version if DisplayVersion is not present. Both 32bit and 64bit registries are searched.
#echo off
setlocal enableDelayedExpansion
set "key="
set "name="
set "ver="
for %%s in (32 64) do (
for /f "delims=" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /reg:%%s 2^>nul') do (
set "ln=%%A"
if "!ln:~0,4!" equ "HKEY" (
if defined name (echo "!name!","!ver!") else if defined key echo "!key!","!ver!"
set "name="
set "ver="
set "key=%%A"
) else for /f "tokens=1,2*" %%A in ("!ln!") do (
if "%%A" equ "DisplayName" set "name=%%C"
if "%%A" equ "DisplayVersion" set "ver=%%C"
)
)
)
if defined name (echo "!name!","!ver!") else if defined key echo "!key!","!ver!"
The easiest method would be to just output the information directly within Windows PowerShell but that would be directly contrary to the tags you've applied to this question.
Here therefore is a batch file which uses Powershell:
#Echo Off
Set "KP=Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
PowerShell -C "GP HKLM:\%KP%\*|Select DisplayName,DisplayVersion|FT -A -H"
Pause
You may remove \Wow6432Node from line 2 if you're not using this on a 64bit Operating System.
It is possible for the DisplayName output to be truncated due to their character lengths and cmd.exe's buffersize. This can be worked around using the following, (possibly crude), code:
#Echo Off
Set "KP=Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
Set/A W=90,H=120
PowerShell -C "&{$H=Get-Host;$R=$H.UI.RawUI;$B=$R.BufferSize;"^
"$W=$R.WindowSize;$B.Width=If (%W% -GT $W.Width) {%W%} Else {$W.Width};"^
"$B.Height=If (%H% -GT $W.Height) {%H%} Else {$W.height};$R.BufferSize=$B};"^
"GP HKLM:\%KP%\*|Select DisplayName,DisplayVersion|FT -A -H"
Pause
In the above code you can adjust that height/width on line 3 as required, this may be necessary if you have some very long DisplayName's or a huge list of installed software under that key.
Related
I am trying to make a batch file, that finds a specific interface (their name vary from computer to computer = query). To find the interface I use a specific IP that is under that interface as a value.
The code here can find the interface in question based on the IP i insert into "IP-ADDRESS".
But my ultimate goal is to based on this search add two registry values into this interface, and therefore I need the path.
How do I get the path into a variable based on the search below?
for /f "tokens=3*" %%a in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\ /s /f "IP-ADDRESS"') do set Myvar=%%b
ECHO %Myvar%
PAUSE
Thank you in advance!
The following batch-file returns here:
> Q:\Test\2018\11\16\SO_53340832.cmd
IPADDRESS:192.168.56.1 on interface:{4fe80965-dda5-466a-801d-14937fd3829c}
It uses "tokens=1,2*" and /v IPADDRESS without dash.
:: Q:\Test\2018\11\16\SO_53340832.cmd
#Echo off & SetLocal EnableExtensions EnableDelayedExpansion
Set "Key=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
Set "Val=IPADDRESS"
For /f "tokens=1,2*" %%A in (
'reg query "%Key%" /s /v "%Val%" ^| findstr /i "^HKEY %Val%"'
) Do if /i "%%A" neq "%Val%" (rem must be HKEY
Set "Interface=%%A"
) Else (
Echo %VAL%:%%C on interface:!Interface:%Key%\=!
)
Here's one possibility for you:
#Echo Off
Set "RKP=HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
Set "RVD=172.26.193.3"
Set "RKC="
For /F "Delims=}" %%A In ('Reg Query "%RKP%" /S /F "%RVD%" /D 2^>Nul'
) Do If Not Defined RKC Set "RKC=%%A}"
If Not Defined RKC Exit /B
Rem show the variable and value for five seconds
Set RKC
Timeout 5 >Nul
i am trying to make an inventory of installed software in domain PCs by following reg command
Reg Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall /S ^| Find /I "DisplayName"
I am using Find /I "DisplayName" to get software-name. I also need the version number (and may be few more fields later), but its in another line as DisplayVersion.
Since I am running this on multiple computers, my script looks like this:
for /f %%i in (computers_ALL.txt) do (
for /f "tokens=1,2,*" %%j in ('psexec \\%%i Reg Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall /S ^| Find /I "DisplayName"') do (
echo x64 %%i %%l >>%OUTPUT_FILE%
)
for /f "tokens=1,2,*" %%j in ('psexec \\%%i Reg Query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /S ^| Find /I "DisplayName"') do (
echo x86 %%i %%l >>%OUTPUT_FILE%
)
)
Now I can only find DisplayName. How can I find DisplayVersion which is on another line and add it to second column? My output will be like,
ComputerName, Platform (32-64 bit), Software Name, Software Version
I can take care upto software-name, but having difficulty to get version and put it on second column. Appreciate your help. Thanks.
Following script works against a local Windows machine. Adapting it for a list computers_ALL.txt instead of "%computername%" and adding psexec \\%_comp% should be a simple task.
#ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
set "OUTPUT_FILE=%temp%\41887529.txt"
for /F %%i in ("%computername%") do (
set "_comp=%%i"
call :proHive "x64" "\Software\Microsoft\Windows\CurrentVersion\Uninstall"
call :proHive "x86" "\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
)
rem debugging output
type "%OUTPUT_FILE%"
ENDLOCAL
goto :eof
:proHive
rem %1 platform
rem %2 registry key
>>"%OUTPUT_FILE%" (
for /f "tokens=*" %%G in ('
Reg Query "HKLM%~2" /S /V DisplayName ^| Find /I "HKEY_LOCAL_MACHINE%~2"
') do (
set "_DisplayName="
set "_DisplayVersion="
for /f "tokens=1,2,*" %%j in ('
Reg Query "%%G" ^| Findstr /I "DisplayName\> DisplayVersion\>"') do set "_%%j=%%l"
SETLOCAL EnableDelayedExpansion
echo %_comp%,%~1,!_DisplayVersion!,!_DisplayName!
ENDLOCAL
)
)
goto :eof
#ECHO OFF
SETLOCAL
SET "output_file=u:\report.txt"
DEL "%output_file%" /F /Q
for /f %%i in (q41887529.txt) do (
SET "compname=%%i"
CALL :clrsoft
FOR %%z IN (\ \Wow6432Node\) DO (
for /f "tokens=1,2,*" %%j in (
'Reg Query HKLM\Software%%zMicrosoft\Windows\CurrentVersion\Uninstall /S ^| Findstr /I "DisplayName DisplayVersion HKEY_LOCAL_MACHINE\\"'
) do (
IF /i "%%j"=="Displayname" (
SET "softname=%%l"
) ELSE (
IF /i "%%j"=="Displayversion" (
SET "softver=%%l"
) ELSE (
CALL :report %%z
)
)
)
REM processed all data - final report
CALL :report %%z
)
)
GOTO :EOF
:: Report routine parameters :
:: %1 indicates x64 ("\") or x86 (\Wow6432Node\)
:report
IF NOT DEFINED softname GOTO clrsoft
IF "%1"=="\" (
ECHO "%compname%",x64,"%softname%","%softver%">>"%output_file%"
) ELSE (
ECHO "%compname%",x86,"%softname%","%softver%">>"%output_file%"
)
:clrsoft
SET "softname="
SET "softver="
GOTO :EOF
Naturally, you'd need to set up your own output filename. I've also removed the psexec \\%%i and set up my machine name in q41887529.txt for testing on my machine.
Since the only difference between the queries is the node, I combined the steps and controlled them using %%z.
Clear the tempvars, then process each return line for one of the three target strings.
If it's a name, then call :report to report any accumulated data, then record the name
If it's a version, record the version and since this should now give us a pair, report it.
If it's neither, then it must be a new key, so report what we have so far.
The wart is that the version need not exist - and the final entry may be versionless, so we try reporting again to ensure any accumulated data is output.
I've revised this now and replaced the original.
It will report the machine name extracted from the file and I believe that the often-missing version number has been fixed - the order of name and version are unpredictable, so the report is triggered with the data accumulated between instances of HKEY_ and at the very end.
I am making a program. When installed, It will run a batch file which needs to know where the application folder is.
The installation wizard software I am using creates a registry key that represents the program's path, but "Program Files" has a space in it, so the batch output will be "C:\Program"
My current script is:
#echo off
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\MarksRTZ\AV"
set VALUE_NAME=DataPath
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
if defined ValueName (
echo data "%ValueValue%"
echo name "%ValueName%"
echo type "%ValueType%"
) else (
echo Not found
)
The DataPath value is set to [APPDIR]\data on installation, [APPDIR] being the location the user selected.
But like I said, that script will always output C:\Program if [APPDIR] was set to something like C:\Program Files (x86)\MarksRTZ\AV\ in the installer (Which is actually the default)
How can I fix this?
I will also note; the batch file isn't the real program, It's going to be the simple script that launches the program in the correct working directory.
Next code snipped should work with tokens=1-2* and even with setlocal DISABLEEXTENSIONS:
rem ensure %ValueName% is not visible as it could be defined already!
set "ValueName="
FOR /F "usebackq skip=2 tokens=1-2*" %%A IN (
`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set "ValueName=%%A"
set "ValueType=%%B"
set "ValueValue=%%C"
)
if defined ValueName (
echo data "%ValueValue%"
echo name "%ValueName%"
echo type "%ValueType%"
) else (
echo Not found
)
Resources:
FOR /F Loop command: against the results of another command;
SETLOCAL Set options to control the visibility of environment variables in a batch file
I have looked in quite a few places. Maybe I have not asked the right question, but I am now here. I am making a batch file to sense what the Operating system is.
My current attempt:
set os=systeminfo |find "OS Name"
EDIT: a WINDOWS batch file
EDIT: If a command returns a line in the console. How do I make a variable = the returned string. (This is my main question. Sorry if I was not very clear.)
Example:
varName = Command |find "String"
#echo off
for /f "delims=" %%a in ('wmic OS get caption ^|find /i "windows"') do (set #OS=%%a)
set #
See how this works for you:
#echo off
setlocal EnableDelayedExpansion
:: Routine by Aacini
::Identify OS
for /F "delims=" %%a in ('ver') do set ver=%%a
set Version=
for %%a in (95=95 98=98 ME=ME NT=NT 2000=2000 5.1.=XP 5.2.=2003 6.0.=Vista 6.1.=7 6.2.=8 6.3=8.1) do (
if "!Version!" equ "this" (
set Version=Windows %%a
) else if "!ver: %%a=!" neq "%ver%" (
set Version=this
)
)
::Identify bit
if exist "%SYSTEMDRIVE%\Program Files (x86)" (
set Type=64 bit
) else (
set Type=32 bit
)
::Display result
echo %Version% %Type%
echo/
pause
this
http://www.robvanderwoude.com/sourcecode.php?src=winver2_nt
and this
http://www.robvanderwoude.com/sourcecode.php?src=winver_bat
should do the work.Not sure if are updated to support Windows 8.
Here are all build numbers.
EDIT (only checks if it is Windows XP or 7 - see comments bellow.Will work also on Windows home editions which have no WMIC command)
#echo off
for /f " tokens=4,5 delims=. " %%a in ('ver') do set /a wver=%%a%%b
if "%wver%" == "61" echo Windows7
if "%wver%" == "51" echo WindowsXP
In bash:
UN=`uname`
echo $UN
In windows you can just examine the OS environment variable:
echo %OS%
Maybe this is what you are looking for:
wmic os get caption /value
There isa lot more of information. Try
wmic os get /value
Here is a routine I wrote to do this. WMIC returns goofy names for some OS's and version number isn't robust enough since some versions are the same for server and workstation. This works for everything.
#echo off
setlocal
call :GetOS cap bit sp
echo %cap%%bit% (%sp%)
exit /b
:GetOS caption servicepack
setlocal
set arc=%PROCESSOR_ARCHITECTURE%
set key="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
for /f "tokens=3*" %%a in (
'reg query %key%^|findstr /i ProductName') do set cap=%%a %%b
for /f "tokens=3*" %%a in (
'reg query %key%^|findstr /i CSDVersion') do set sp=%%a %%b
endlocal & set %1=%cap% & set %2=%arc% & set %3=%sp%
exit /b
I need to use a REG QUERY command to view the value of a key and set the result into a variable with this command:
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "KeyName" /v ValueName') DO SET Variable=%%B
But if the key doesnt exists i get an error shown in the console. I need to hide this error! I tried putting a 2>nul after the command to stop the stderr, but this works if i only call the command:
REG QUERY "KeyName" /v ValueName 2>nul
If i put it into the FOR command like this:
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "KeyName" /v ValueName') DO SET Variable=%%B 2>nul
The error is shown.
So does anyone know how to hide the error? Or maybe another command too see if a key exists or not?
Thanks
PS: I'm using Windows XP
This works for me:
#echo OFF
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_CURRENT_USER\Software\Microsoft\Command Processor"
set VALUE_NAME=DefaultColor
FOR /F "usebackq skip=4 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
if defined ValueName (
#echo Value Name = %ValueName%
#echo Value Type = %ValueType%
#echo Value Value = %ValueValue%
) else (
#echo %KEY_NAME%\%VALUE_NAME% not found.
)
usebackq is needed since the command to REG QUERY uses double quotes.
skip=4 ignores all the output except for the line that has the value name, type and value, if it exists.
2^>nul prevents the error text from appearing. ^ is the escape character that lets you put the > in the for command.
When I run the script above as given, I get this output:
Value Name = DefaultColor
Value Type = REG_DWORD
Value Value = 0x0
If I change the value of VALUE_NAME to BogusValue then I get this:
"HKEY_CURRENT_USER\Software\Microsoft\Command Processor"\BogusValue not found.
This work for me with variable that contains spaces on Windows 7:
FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\Software\SomeAPP" /v ValueName`) DO (
set appdir=%%A %%B
)
ECHO %appdir%
Variable A contains all data before first space, B - rest part of ValueName (including further spaces), so appdir = ValueName
This one-liner is pretty much the same as your original try with a couple of additions. It works with paths including spaces, and works in both XP and Windows 7 even if the key is not found (and hides the error). %fn% will be empty if the key does not exist. This example gets the current desktop background filename:
for /f "tokens=2*" %%a in ('reg query "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper 2^>^&1^|find "REG_"') do #set fn=%%b
This command uses tokens=2* with %%a as the loop variable but consumes %%b to correctly handle spaces. When using tokens=2*, the loop variable %%a is assigned the value in the second token (in this case, REG_SZ) and %%b is assigned the remainder of the line after the next group of delimiter characters, including all internal delimiter characters. This means that %%b will correctly replicate delimiter characters—even if multiple delimiter characters are clustered together. For example, the value might be C:\A weird path\blah.png. This technique of reading the value would correctly preserve the two spaces between C:\A and weird.
Based on tryingToBeClever solution (which I happened to also stumble upon and fixed myself by trial-and-error before finding it), I also suggest passing the result output of reg query through find in order to filter undesired lines due to the ! REG.EXE VERSION x.y inconsistency. The find filtering and tokens tweaking also allows to pick exactly what we want (typically the value). Also added quotes to avoid unexpected results with key/value names containing spaces.
Final result proposed when we are only interested in fetching the value:
#echo off
setlocal ENABLEEXTENSIONS
set KEY_NAME=HKCU\Software\Microsoft\Command Processor
set VALUE_NAME=DefaultColor
for /F "usebackq tokens=1,2,*" %%A IN (`reg query "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul ^| find "%VALUE_NAME%"`) do (
echo %%C
)
A potential caveat of using find is that the errorlevel set by reg when errors occur is now obfuscated so one should only use this approach for keys known to be there and/or after a previous validation.
A tiny additional optimization (add skip=1 to avoid processing the first line of output) can be done in cases when the key name also contains the value name (as it is the case with HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion and CurrentVersion) but removes most flexibility so should only be used in particular use-cases.
#echo off
setlocal ENABLEEXTENSIONS
set KEY_NAME=HKLM\SOFTWARE\Wow6432Node\Acme Software Inc\Common
set VALUE_NAME=InstallDir
FOR /F "tokens=2*" %%A IN ('REG.exe query "%KEY_NAME%" /v "%VALUE_NAME%"') DO (set pInstallDir=%%B)
echo %pInstallDir%
That works for me in Win7 where the key has a space and the value also has a space.
So saving the above in c:\temp as test.bat, open a cmd window and run it.
C:\temp>test
C:\Program Files (x86)\acme Software Inc\APP\
For some reason Patrick Cuff's code doesn't work on my system (Windows 7) probably due to tryingToBeClever's comment. Modifying it a little did the trick:
#echo OFF
setlocal ENABLEEXTENSIONS
set KEY_NAME=HKEY_CURRENT_USER\Software\Microsoft\Command Processor
set VALUE_NAME=DefaultColor
FOR /F "tokens=1-3" %%A IN ('REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul') DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
if defined ValueName (
#echo Value Name = %ValueName%
#echo Value Type = %ValueType%
#echo Value Value = %ValueValue%
) else (
#echo %KEY_NAME%\%VALUE_NAME% not found.
)
For Windows 7 (Professional, 64-bit - can't speak for the others) I see that REG no longer spits out
! REG.EXE VERSION 3.0
as it does in XP. So the above needs to be modified to use
skip=2
instead of 4 - which makes things messy if you want your script to be portable. Although it's much more heavyweight and complex, a WMIC based solution may be better.
This works if the value contains a space:
FOR /F "skip=2 tokens=1,2*" %%A IN ('REG QUERY "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul') DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
if defined ValueName (
echo Value Name = %ValueName%
echo Value Type = %ValueType%
echo Value Value = %ValueValue%
) else (
#echo "%KEY_NAME%"\"%VALUE_NAME%" not found.
)
Great level of solutions here.
My little grain of salt as the solution #Patrick Cuff did not work out of the box; I had 2 problems
I use Windows 7 => changed to "skip=2"
The value of the registry value had a space in it Value Value = C:\Program Files\...
Here is the solution I found: taking 4 tokens and setting ValueValue to %%C and %%D. (Thanks #Ivan!)
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_CURRENT_USER\Software\Microsoft\Command Processor"
set VALUE_NAME=DefaultColor
FOR /F "usebackq skip=2 tokens=1-4" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C %%D
)
if defined ValueName (
#echo Value Name = %ValueName%
#echo Value Type = %ValueType%
#echo Value Value = %ValueValue%
) else (
#echo "%KEY_NAME:"=%\%VALUE_NAME%" not found.
)
To get a particular answer to the registry value you may use the following query:
REG QUERY "Key_Name" /v "Value_Name" /s
eg:
REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v "EnableExtensions" /s
here
/v : Queries for a specific registry key values.
/s : Queries all subkeys and values recursively (like dir /s)
Thanks, i just need to use:
SETLOCAL EnableExtensions
And put a:
2^>nul
Into the REG QUERY called in the FOR command.
Thanks a lot again! :)
#echo off
setlocal ENABLEEXTENSIONS
set KEY_NAME=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\awhost32.exe
set VALUE_NAME=Path
for /F "usebackq tokens=3" %%A IN (`reg query "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul ^| find "%VALUE_NAME%"`) do (
echo %%A
)
How do you handle a space in the %%A variable? This results in C:\Program. The actual path is C:\Program Files\Symantec\pcAnywhere.
echo Off
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup"
set VALUE_NAME=release
REG QUERY %KEY_NAME% /S /v %VALUE_NAME%
endlocal
dot put \ at the end of KEY_NAME
I've come across many errors on Windows XP computers when using WMIC (eg due to corrupted files on machines). Hence imo best not to use WMIC for Win XP in code. No problems with WMIC on Win 7 though.
You can get the value of a registry key as follows
#echo OFF
setlocal ENABLEEXTENSIONS
set REG_NAME="HKEY_CURRENT_USER\Software\Test"
set KEY_NAME=TestVal
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %REG_NAME% /v %KEY_NAME% 2^>nul`) DO (
#echo %%A : %%C
)
pause
those who wonder how to add reg keys, here is a way.
REGEDIT4
; #ECHO OFF
; CLS
; REGEDIT.EXE /S "%~f0"
; EXIT
[HKEY_CURRENT_USER\Software\Test]
"TestVal"="Succeeded"
With regedit:
#echo off
setlocal
::if the scrit is not ran as administrator
:: and the key does not require admin permissions
set __COMPAT_LAYER=RunAsInvoker
set "key=%~1"
set "value=%~2"
regedit /e "#.reg" "%key%"
for /f "tokens=1,* delims==" %%a in ('find """%value%""=" "#.reg"') do if "%%~b" neq "" echo %%~b
del /q #.reg
endlocal
Example:
call regreader.bat "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup\1033\" Version
output:
3.0.30729.4926
set regVar_LocalPrjPath="LocalPrjPath"
set regVar_Path="HKEY_CURRENT_USER\Software\xyz\KeyPath"
:: ### Retrieve VAR1 ###
FOR /F "skip=2 tokens=2,*" %%A IN ('reg.exe query %regVar_Path% /v %regVar_LocalPrjPath%') DO set "VAR1=%%B"
You can also use this solution with a single command line:
VARIABLE=$(reg query "HKLM\REGISTRYKEYPATH" /v "REGISTRY KEY" | grep -i "REGISTRY KEY" | awk '{print $NF;}')
For your information $NF retrieves the last field (which is the registry key value).