[batch-file] How can I get the value of a registry key from within a batch script?

This work for me with variable that contains spaces on Windows 7:

FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\Software\SomeAPP" /v ValueName`) DO (
    set appdir=%%A %%B
    )
ECHO %appdir%

Variable A contains all data before first space, B - rest part of ValueName (including further spaces), so appdir = ValueName