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.

Syntax

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.

Example

@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\

Output

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	
batch_script_registry.htm
Advertisements