Batch Script - Reading from the 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 [ROOT\]RegKey /ve --This returns the (default) value

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


@echo off 
REG QUERY HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\

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


The output will display all the keys and values under the registry key.


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

   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