Skip to main content

Batch Script Reading from Registry

Reading from Registry​

Reading from the registry is done via the reg query command.

This command can be used to retrieve values of any key from within the registry.

reg query [root\]RegKey /v ValueName [/s]
reg query [rott\]RegKey /ve --This returns the (default) value

where RegKey is the key which needs to be searched for in the registry.

Example​

The following command will query all the keys and their respective values under the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\

@echo off
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\

The output will display all the keys and values under the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\.

This location in the registry has some key information about the Windows system such as the System Directory location.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows
Directory REG_EXPAND_SZ %SystemRoot%
SystemDirectory REG_EXPAND_SZ %SystemRoot%\system32
NoInteractiveServices REG_DWORD 0x1
CSDBuildNumber REG_DWORD 0x4000
ShellErrorMode REG_DWORD 0x1
ComponentizedBuild REG_DWORD 0x1
CSDVersion REG_DWORD 0x0
ErrorMode REG_DWORD 0x0
CSDReleaseType REG_DWORD 0x0
ShutdownTime REG_BINARY 3AFEF5D05D46D101