windowsbatch-file

How to read (Default) value from registry and put into a variable within a batch file?


I know there are a lot of questions with reading values from registry, set to a variable in a bat file, but i did not figure out how the read the (default) value??
If I use

Reg.exe QUERY "HKLM\SOFTWARE\Wow6432Node\Notepad++"


I will get

(Default) REG_SZ C:\ProgramFiles (x86)\Notepad++

but if I use the code:

@echo OFF
Reg.exe QUERY "HKLM\SOFTWARE\Wow6432Node\Notepad++"
setlocal ENABLEEXTENSIONS
FOR /F "usebackq skip=2 tokens=1-3" %%A IN ('Reg QUERY "HKLM\SOFTWARE\Wow6432Node\Notepad++" ') DO (
set ValueType=%%B
set ValueValue=%%C
)
if defined ValueType(
@echo Value Type = %ValueType%
@echo Value Value = %ValueValue%
) else (
@echo not found.
)

I get the error: "The syntax of the command is incorrect"
What I want is to put into ValueValue = C:\ProgramFiles (x86)\Notepad++
Someone can help me?


Solution

  • From the cmd line:

    for /f "tokens=3*" %a in ('reg query "HKLM\SOFTWARE\Wow6432Node\Notepad++"') do echo %a %b
    

    if you want to do it in script, double the %'s