2

I want to read the registry key which has space in it. If I read, how can I skip the REG_SZ in the output.

I tried

FOR /F "tokens=*" %%A IN ('%SystemRoot%\system32\REG.exe QUERY "HKLM\SOFTWARE\Wow6432Node\PostgreSQL\Installations\postgresql-9.0" /v "Base Directory"  ^| find /i "REG_SZ"') DO set pghome=%%B
echo %pghome% 
cd /d %pghome%

Output is

C:\Users\test>set pghome=%B
C:\Users\test>echo %B
%B
C:\Users\test>cd /d %B
The system cannot find the path specified.

How can I read the path from the registry and navigate to it

1
  • do you execute this from command line or from a batch file?
    – npocmaka
    Dec 9, 2013 at 12:17

1 Answer 1

3

If you are reading the line with the required value filtering for the REG_SZ, you will get a line as (sorry i've not postgresql to test)

Base Directory    REG_SZ    C:\ProgramFiles\ .....

Since for /f command is by default using spaces (and more characters) as separators, what you have is a line with, at least, 4 tokens: Base, Directory, REG_SZ, C:\... and if the value contains spaces, aditional tokens will be available.

What is needed is all information from 4th and following tokens, so the better option will be

for /f "tokens=3,*" %%a in ....

That way, %%a will hold REG_SZ and %%b the rest of the line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.