This works for me:
@echo OFF setlocal ENABLEEXTENSIONS set KEY_NAME="HKEY_CURRENT_USER\Software\Microsoft\Command Processor" set VALUE_NAME=DefaultColor FOR /F "usebackq skip=4 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO ( set ValueName=%%A set ValueType=%%B set ValueValue=%%C ) if defined ValueName ( @echo Value Name = %ValueName% @echo Value Type = %ValueType% @echo Value Value = %ValueValue% ) else ( @echo %KEY_NAME%\%VALUE_NAME% not found. )
usebackq necessary because the REG QUERY command uses double quotes.
skip=4 ignores all output, except for a string that has a name, type, and value if it exists.
2^>nul prevents error text from appearing. ^ is an escape character that allows you to put > in a for command.
When I run the script above as indicated, I get this output:
Value Name = DefaultColor Value Type = REG_DWORD Value Value = 0x0
If I change the value of VALUE_NAME to BogusValue , then I get the following:
"HKEY_CURRENT_USER\Software\Microsoft\Command Processor"\BogusValue not found.
Patrick Cuff Jan 15 '09 at 1:23 2009-01-15 01:23
source share