how to read registry string value from batch file
I want to read registry string value, from bat file, and then assing the readed value to v开发者_运维问答ariable. I tried the following :
FOR %%a in ('REG QUERY HKLM\SOFTWARE\MathWorks\MATLAB\7.10 /v MATLABROOT') DO set MATLAB=%%a
echo %MATLAB%
but it doesn't work.
If the name of the value (baz in this case) does not contain spaces you can do something like
FOR /F "skip=4 tokens=2,*" %%A IN ('REG.exe query "HKLM\software\foo\bar" /v "baz"') DO set "MATLABROOT=%%B"
If the name is dynamic and only known at run time, you would have to use tokens=* and parse %%A looking for "REG_" so you know where the data starts...
reg
prints out way more than just the very value you're interested in. As far as I can see, giving the skip=2
and tokens=3
option to for
might work.
Might need to get a little more elaborate than that, though, if there are more spaces than anticipated.
精彩评论