Programming Field

Reg Add - DOS/Command Prompt Reference

[Windows NT series/XP or later] Adds or modifies keys and values in the registry. This is one of the operations of Reg command.

This page covers commands that allow you to modify the Windows registry. As the registry contains important settings for Windows, please proceed with caution when making changes. It is strongly recommended to create a backup before manipulating the registry, especially if you are not familiar with registry operations. Making inadvertent changes to various data can lead to Windows not starting up properly. Please note that we cannot take responsibility for any issues that may arise from using the information on this page.

Syntax

reg[.exe] add <key> [/v <var-name> | /ve]
    [/t <type>] [/s <separator>] [/d <data>]
    [/f] [/reg:[32|64]]

Options

<key>

Specifies the key name. For specific instructions on how to specify the key name, please refer to ‘About specifying key names’.

The key name is specified with a complete path, and if intermediate subkeys do not exist, they will be created. Therefore, if you want to create a specific key, you can specify the full path, including the key name, here to create it.

/v <var-name> | /ve

If using ‘/v <var-name>’, specifies the name of the value you want to set for <var-name>. The name must be a standalone name and cannot include a pathname (the path should be included in <key>).

If using ‘/ve’, Reg sets the value of the ‘Default’ (or ‘Standard’, unnamed) value in the specified key.

If not specifying ‘/v’ and ‘/ve’, ‘/ve’ is used.

* Due to this specification, when creating a new key, it is not possible to set the ‘Default’ value to ‘Not set’. If you do not want the ‘Default’ value, you need to delete it using ‘Reg Delete’.

/t <type>

Specifies the data type to set. <type> will be the value type. Please refer to ‘Value types’ for the available options.

If this option is omitted, it is treated as if ‘REG_SZ’ is specified.

/s <separator>

Specifies the character to use as a separator when setting a value with the type ‘REG_MULTI_SZ’ (7). <separator> will be a single character.

If this option is not specified, it uses the two characters ‘\0’ as the separator (‘\0’ cannot be specified for <separator>).

/d <data>

Specifies the content (data) when adding a value.

If the value type is ‘REG_DWORD’ (4), ‘REG_DWORD_BIG_ENDIAN’ (5), or ‘REG_QWORD’ (11), <data> will be an integer in decimal or a hexadecimal integer with ‘0x’ prefixed.

If the value type is ‘REG_SZ’ (1), ‘REG_EXPAND_SZ’ (2), or ‘REG_MULTI_SZ’ (7), <data> will be a string. Values set for ‘REG_EXPAND_SZ’ typically include the ‘%’ character, so in command-line/batch file contexts, it is necessary to use ‘^’ to prevent ‘%’ from being treated as expanding an environment variable ‘%’. Additionally, since the pair ‘" "’ is automatically removed, if you want to include ‘"’ as a value character, you need to specify it as ‘"""’ with three consecutive characters.

* When setting the value with ‘REG_DWORD_BIG_ENDIAN’, the ‘Registry Editor’ produces different results in byte order. For example, if you set the value ‘1000’ (0x3E8) with Reg Add, Reg Add will set the value as ‘E8 03 00 00’ in binary data (might be a mistake), but when you view it in the Registry Editor, the result is ‘3892510720’ (0xE8030000). (Confirmed on Windows 10 Build 14393).

/f Overwrites (replaces) the data if it already exists. If the /f option is omitted, a prompt will be displayed asking whether to overwrite if a value with the same name already exists.
/reg:[32|64]

If there is an environment with both 64-bit and 32-bit versions (WOW64), specifying ‘/reg:32’ will reference registry data used by 32-bit applications (for example, ‘HKLM\Software\WOW6432Node’ for HKLM), and specifying ‘/reg:64’ will reference registry data used by 64-bit applications.

If this option is omitted, the executed Reg.exe will reference the registry corresponding to its bit version. If it is a 64-bit version, it will reference the 64-bit registry; if it is a 32-bit version (located under %SystemRoot%\SysWOW64), it will reference the 32-bit registry. If you want to reference registry data for a specific application and know whether it's 32-bit or 64-bit, you can explicitly specify this option to avoid ambiguity.

* Even if Reg.exe is a 32-bit version, you can reference the 64-bit registry by using ‘/reg:64’.
* If you are using the 64-bit version of Reg.exe, you can also directly specify keys such as ‘HKLM\Software\WOW6432Node’ when referencing the 32-bit registry.

Details

Usage of Reg Add

The ‘ADD’ command in Reg is used to create or modify values within the registry. Even when simply overwriting a value, the ‘ADD’ command is used.

When using the /f option to create or overwrite a value, it does not prompt for confirmation if the value already exists. Since the overwritten value cannot be restored, using this option without understanding what value you are overwriting may lead to unexpected issues. In such cases, it is advisable to perform backups in advance using commands like ‘SAVE’ or ‘EXPORT’.

Samples

Sample 1

reg add "HKCU\Software\My Company\MyApp" /v StartupPath /d "%CD%"

[Extensions] Sets the value ‘StartupPath’ within the ‘HKEY_CURRENT_USER\Software\My Company\MyApp’ key to the current directory.

Sample 2

reg add HKCU\Software\Classes\MyFileType\DefaultIcon /ve /f /t REG_EXPAND_SZ /d ^%SystemRoot^%\System32\imageres.dll,17

Set the value of the ‘DefaultIcon’ key under ‘HKEY_CURRENT_USER\Software\Classes\MyFileType’ and its subkeys to the ‘Default Value’ of ‘%SystemRoot%\System32\imageres.dll,17’. To specify environment variables as values without expanding them on the command line, set the type to ‘REG_EXPAND_SZ’ and use the ‘^’ character to prevent the interpretation of ‘%’ on the command line. Note that the ‘/f’ option will overwrite the value if it is already set.

* When using it in a batch file, you should write ‘%%’ instead of ‘^%’.
* If you want to use ‘^%’ on the command line, you cannot enclose it with ‘" "’ (otherwise the ‘^’ character will be written as is). Therefore, if you want to include a space character, you need to execute it from a batch file.

See also