I want to read registry string value, from bat file, and then assing the readed value to variable. 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.
Use the GetValue method, specifying the path and name) to read a value from registry key. The following example reads the value Name from HKEY_CURRENT_USER\Software\MyApp and displays it in a message box.
You can use Get-ChildItem to view registry keys and Set-Location to navigate to a key path. Registry values are attributes of a registry key. In the Registry drive, they are called Item Properties. A registry key can have both children keys and item properties.
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With