Search code examples
filebatch-fileregistrytoken

reg query value with many spaces


I'm having a bit of a bother getting my head around delims / tokens to deal with a reg query on a value which contains several spaces, for example "one two three four five six seven eight"

for /f "skip=2 tokens=2,3*" %%A in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Values\manyvalues" /v manyvalues') DO (for %%F in (%%B) do (set manyvalues=%%F))

echo %manyvalues%

Any ideas on how to deal with this please?

Thanks B


Solution

  • for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Values\manyvalues" /v "manyvalues"') do set manyvalues=%%a
    

    Is an alternative way. delims= sets the delimiter to nothing by closing the options straight after the equal sign, it's space or tab if not specified.

    The advantage of this is that it doesn't matter how many spaces there is in the string.