I\'m struggling to read the value of a registry key into a variable. The registry value may, or may not, contain spaces. In this case I\'m trying to look up SDK paths.
I
Use Quotation marks
SET "sdkpath=%%M"
instead SET sdkpath=%%M
This will avoid problems with spaces.
Ah this is one of the annoying details about the for /f
command. In order to read all the characters including the spaces with the *
the previous token needs to be declared. tokens=2,*
The functional reason is stated in the documentation.
If the last character in the tokens= string is an asterisk (*), an additional variable is allocated and receives the remaining text on the line after the last token that is parsed.
FOR Documentation
FOR /F "usebackq tokens=2,* skip=2" %%L IN (
`reg query "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDKTools" /v InstallationFolder`
) DO SET sdkpath=%%M