The possibly most useful combination of options
The most useful combination of options is probably /s
with /f
: it recursively searches for everything that matches a given value (also as substring).
C:\> reg query HKLM /s /f someData
Examples with test data
The following
batch files attempt to demonstrate a few flags and usages of
reg query
.
insert-values.bat
@echo off
rem
rem Creating keys
rem =============
rem A key can be created by specifying
rem it's path after "reg add".
reg add HKCU\Software\tq84 > nul
rem
rem It's not necessary to add path componenents
rem one by one. reg is clever enough to create
rem all needed keys (here: apple and banana) before
rem creating the last one (cherry)
reg add HKCU\Software\tq84\apple\banana\cherry > nul
rem
rem Add a few values
rem /v specifies the name of the value
rem /d specifies its value
rem /t specifies the values data type
rem /ve is used to write a key's default value
rem
rem
reg add HKCU\Software\tq84\apple /v valOne /t REG_SZ /d foo > nul
reg add HKCU\Software\tq84\apple\banana /v valTwo /t REG_SZ /d bar > nul
reg add HKCU\Software\tq84\apple /v valThree /t REG_SZ /d baz > nul
reg add HKCU\Software\tq84\apple\banana /ve /t REG_SZ /d apple > nul
reg add HKCU\Software\tq84\apple\banana\cherry /v apple /t REG_SZ /d fruit > nul
rem
rem Wait for the user to check the newly created keys
rem with regedit:
rem
show.bat
show.bat
demonstrates a few queries below the newly inserted HKEY_CURRENT_USER\Software\tq84
key.
@echo off
rem
echo ** Show the values and keys of a given key
rem
@ reg query HKCU\Software\tq84\apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple
rem valOne REG_SZ foo
rem valThree REG_SZ baz
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana
rem
echo ** Show a key and all its subkeys and values recursively
rem
@ reg query HKCU\Software\tq84 /s
rem
rem HKEY_CURRENT_USER\Software\tq84
rem (Default) REG_SZ
rem
rem HKEY_CURRENT_USER\Software\tq84\apple
rem valOne REG_SZ foo
rem valThree REG_SZ baz
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana
rem valTwo REG_SZ bar
rem (Default) REG_SZ apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana\cherry
rem (Default) REG_SZ
rem apple REG_SZ fruit
rem
echo ** Find values whose name is apple **
rem
@ reg query HKCU\Software\tq84 /s /v apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana\cherry
rem apple REG_SZ fruit
rem
rem
echo ** Find everything with apple: keys, value-names and values.
rem /v specifically searches for values, /f searches for
rem everything.
rem
@ reg query HKCU\Software\tq84 /s /f apple
rem
echo ** Restrict previous query to key names only by adding the /k flag
rem
@ reg query HKCU\Software\tq84 /s /f apple /k
rem
rem HKEY_CURRENT_USER\Software\tq84\apple
rem
rem
echo ** Restrict previous query to searching in data using the /d flag:
rem
@ reg query HKCU\Software\tq84 /s /f apple /d
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana
rem (Default) REG_SZ apple
rem
rem
echo ** Searching with a substring (part) of the searched item
rem
@ reg query HKCU\Software\tq84 /s /f ppl
rem
rem HKEY_CURRENT_USER\Software\tq84\apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana
rem (Default) REG_SZ apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana\cherry
rem apple REG_SZ fruit
cleanup.bat
Finally, cleanup.bat
removes the HKEY_CURRENT_USER\Software\tq84
key entirely.
@echo off
rem
echo ** Show the values and keys of a given key
rem
@ reg query HKCU\Software\tq84\apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple
rem valOne REG_SZ foo
rem valThree REG_SZ baz
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana
rem
echo ** Show a key and all its subkeys and values recursively
rem
@ reg query HKCU\Software\tq84 /s
rem
rem HKEY_CURRENT_USER\Software\tq84
rem (Default) REG_SZ
rem
rem HKEY_CURRENT_USER\Software\tq84\apple
rem valOne REG_SZ foo
rem valThree REG_SZ baz
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana
rem valTwo REG_SZ bar
rem (Default) REG_SZ apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana\cherry
rem (Default) REG_SZ
rem apple REG_SZ fruit
rem
echo ** Find values whose name is apple **
rem
@ reg query HKCU\Software\tq84 /s /v apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana\cherry
rem apple REG_SZ fruit
rem
rem
echo ** Find everything with apple: keys, value-names and values.
rem /v specifically searches for values, /f searches for
rem everything.
rem
@ reg query HKCU\Software\tq84 /s /f apple
rem
echo ** Restrict previous query to key names only by adding the /k flag
rem
@ reg query HKCU\Software\tq84 /s /f apple /k
rem
rem HKEY_CURRENT_USER\Software\tq84\apple
rem
rem
echo ** Restrict previous query to searching in data using the /d flag:
rem
@ reg query HKCU\Software\tq84 /s /f apple /d
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana
rem (Default) REG_SZ apple
rem
rem
echo ** Searching with a substring (part) of the searched item
rem
@ reg query HKCU\Software\tq84 /s /f ppl
rem
rem HKEY_CURRENT_USER\Software\tq84\apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana
rem (Default) REG_SZ apple
rem
rem HKEY_CURRENT_USER\Software\tq84\apple\banana\cherry
rem apple REG_SZ fruit