简体   繁体   English

读取批处理文件中具有空间的注册表项?

[英]Read registry key which has space in batch file?

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. 如果阅读,如何跳过输出中的REG_SZ。

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 如何从注册表中读取路径并导航到该路径

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) 如果您正在读取具有REG_SZ所需值过滤的行,则将得到一行为(对不起,我没有Postgresql进行测试)

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. 由于默认情况下for /f命令使用空格(和更多字符)作为分隔符,因此您所拥有的一行至少带有4个标记: BaseDirectoryREG_SZC:\\... ,并且该值包含空格,其他令牌也将可用。

What is needed is all information from 4th and following tokens, so the better option will be 所需的是来自第4个及以下令牌的所有信息,因此更好的选择是

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

That way, %%a will hold REG_SZ and %%b the rest of the line. 这样, %%a将保留REG_SZ%%b将保留其余部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM