Skip to main content

Batch Script Adding to Registry

Adding to Registry

Adding to the registry is done via the reg add command. Note that in order to add values to the registry you need to have sufficient privileges on the system to perform this operation.

The reg add command has the following variations. In the second variation, no name is specified for the key and it will add the default name for the key.

reg add [root\]RegKey /v ValueName [/t DataType] [/S Separator] [/d Data] [/f]
reg add [root\]RegKey /ve [/d Data] [/f]

where:

  • ValueName The value, under the selected RegKey, to edit.
  • /d Data The actual data to store as a "String", integer, etc.
  • /f Force an update without prompting "Value exists, overwrite Y/N".
  • /S Separator Character to use as the separator in REG_MULTI_SZ values. The default is \0.
  • /t DataType These are the data types defined as per the registry standards which can be:
    • REG_SZ (default)
    • REG_DWORD
    • REG_EXPAND_SZ
    • REG_MULTI_SZ

Example

In the following example, the first part is to add a key into the registry under the location HKEY_CURRENT_USER\Console. This key will have a name of Test and the value assigned to the key will be Test Data which will be of the default string type. The second command just displays what was added to the registry by using the reg query command.

@echo off 
reg add HKEY_CURRENT_USER\Console /v Test /d "Test Data" REG QUERY HKEY_CURRENT_USER\Console /v Test

The output of the above program is shown below. The first line of the output shows that the 'Add' functionality was successfully executed and the second line shows the value entered into the register.

The operation completed successfully.
HKEY_CURRENT_USER\Console
Test REG_SZ Test Data

Table of Contents