Programming Field

Reg - DOS/Command Prompt Reference

[Windows NT series/XP or later] Performs general operations related to the registry, such as retrieving and modifying registry values.

Syntax

reg[.exe] <operation> <parameters>

Options

<operation>

Specifies operations for the registry. Specify one of the following.

QUERYPerforms value retrieval (output) and searches for values and keys.
ADDAdds or modifies values and keys.
DELETEDeletes values and keys.
COPYCopies values and keys to a different parent key entirely.
SAVEWrites a specific key and its data, including the data within it, to a registry data file (hive).
RESTOREExpands (restores) data from the specified key in a registry data file (hive).
LOADTreats a registry data file (hive) as a registry key, allowing direct access to its internal keys and data.
UNLOADCloses (unloads) the key from the registry data file (hive) loaded with LOAD.
COMPARECompares the contents of the specified keys.
EXPORTWrites the specified key and its contents to a .reg file (registration entry file).
IMPORTRegisters the contents of a .reg file (registration entry file) into the registry.
FLAGSRetrieves (outputs) or modifies registry virtualization settings (flags) for keys under HKEY_LOCAL_MACHINE\Software.
<parameters>

Specifies parameters for the <operations> to use. For details, please refer to the page that describes each operation.

All operations except for ‘REG IMPORT’ specify the key name as the first <parameters>. Please refer to the Details on specifying key names.

Details

Reg is a program that performs registry operations based on the specified parameters. In contrast to ‘Regedit’ (Registry Editor), which allows registry operations through a graphical user interface (GUI), this program is well-suited for performing registry operations using command-line batch files.

The execution results and required parameters vary depending on the operation specified in <operations>. For details, please refer to the individual pages using the following links.

Reg returns the following exit codes, which can be used when branching the process using constructs such as If Errorlevel.

0The operation was successful.
1The operation failed (data not found, insufficient permissions, etc.).
2(REG COMPARE only) The operation was successful, but the comparison content did not match.

Note that error messages are output to standard error (STDERR) rather than standard output (STDOUT). When dealing with standard output using various redirections (such as ‘>’) or the For command, if you want to suppress the output of standard error to the screen, you need to use something like ‘2> NUL’.

About specifying key names

With the exception of ‘REG IMPORT’, each operation specifies the key name as the first <parameters> (for ‘REG COPY’ and ‘REG COMPARE’, it is also specified as the second parameter). The key name must be specified with the full path, and its format is as follows.

[\\<computer>\]<root-key>[\<key-path>]
<computer>
Specifies the computer name. If you have the necessary permissions, you can perform registry operations on the specified computer. It must be specified in the format ‘\\ComputerName\’ before the root key. If omitted, the computer executing the command is used.
* If the computer name refers to a remote computer, you can only use either HKEY_LOCAL_MACHINE or HKEY_USERS for <root-key>.
* In some commands, specifying a computer name may not be allowed, and they may be limited to the local computer only (any such limitations are noted on each command page).
<root-key>
Specifies the name of the root key. You can use names like HKLM or HKCU. Both abbreviated names with 3 or 4 characters and unabbreviated names (the actual names of the root keys) such as HKEY_* are allowed.
NameActual root keyDescription
HKLMHKEY_LOCAL_MACHINEPrimarily contains settings for the entire system.
HKCUHKEY_CURRENT_USERContains settings for the current session's user (logged-in user). It corresponds to the content under the subkey pointing to the corresponding user under HKEY_USERS.
HKCRHKEY_CLASSES_ROOTContains settings used for file associations, COM (Component Object Model), and similar purposes. It combines the contents of HKEY_CURRENT_USER\Software\Classes and HKEY_LOCAL_MACHINE\Software\Classes.
HKUHKEY_USERSContains settings for all users known to the system.
HKCCHKEY_CURRENT_CONFIGContains settings specific to the current hardware. It is treated as equivalent to the content under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\Current.
* Each root key HKEY_CURRENT_USER_LOCAL_SETTINGS, HKEY_DYN_DATA, HKEY_PERFORMANCE_DATA, HKEY_PERFORMANCE_NLSTEXT, and HKEY_PERFORMANCE_TEXT cannot be used with Reg.
<key-path>
Places ‘\’ immediately after the root key, and then specifies the subkey's name immediately after that when specifying the name of a subkey. Similar to specifying child keys and their grandchildren in a file path, you can use ‘\’ as a separator, such as ‘a\b’.

Including the root key, the specified path takes the form of ‘HKCU\Software\Microsoft’, for example.

Value types

For some operations like ‘REG ADD’, there is an option to specify the data type of the registry value. The available value types can be specified using either the ‘constant name’ or ‘numeric value’ type from the types listed below (note that constant names in parentheses cannot be used). Additionally, while ‘numeric value’ can include values not listed in the table, undefined types may be ignored by the system or applications.

Constant nameNumeric valueMeaningDetails
REG_NONE0Undefined valuePrimarily used when the mere presence of the value itself has significance (not commonly used).
REG_SZ1StringStores a regular string.
REG_EXPAND_SZ2Expandable stringYou can include the name of an environment variable as a value, like ‘%ENVNAME%’. (*1)
REG_BINARY3Binary dataHolds data that cannot be represented in a string. In Reg, 1 byte is represented as a two-digit hexadecimal number, and the notation uses concatenated hexadecimal numbers without separators. (*2)
REG_DWORD
REG_DWORD_LITTLE_ENDIAN
432-bit numeric value (little-endian)used when the data being handled is a value that fits into (32 bits) and is known to be a numerical value (can also be replaced with REG_BINARY). In Reg, values starting with ‘0x’ are treated as hexadecimal, while others are treated as decimal.
REG_DWORD_BIG_ENDIAN532-bit numeric value (big-endian)Used when handling data of type REG_DWORD in big-endian format. Since ‘REG_DWORD’ is treated as little-endian even without explicitly stating ‘REG_DWORD_LITTLE_ENDIAN’, this type needs to be used if you want to treat it as big-endian.
(REG_LINK)6LinkUsed for a value that holds the reference to the destination of a key created for linking purposes. (*3)
REG_MULTI_SZ7Multi-line stringUsed when holding multiple strings, such as lists or arrays, as a single value. (*4)
(REG_RESOURCE_LIST)8List of resources for resource mapping(Details not investigated; mainly used in hardware/drivers.) (*5)
(REG_FULL_RESOURCE_DESCRIPTOR)9List of resources for hardware identifiers(Details not investigated; mainly used in hardware/drivers.) (*5)
(REG_RESOURCE_REQUIREMENTS_LIST)10List of resources for resource mapping(Details not investigated; mainly used in hardware/drivers.) (*5)
REG_QWORD
(REG_QWORD_LITTLE_ENDIAN)
1164-bit numeric value (little-endian)Used when there is a possibility that the data being handled may exceed 32 bits and is known to be a value that fits into 64 bits (can also be replaced with REG_BINARY). In Reg, values starting with "0x" are treated as hexadecimal, while others are treated as decimal. Note that there is no type that supports big-endian (as of Windows 10 Build 10586).

*1: The expansion of environment variables is performed by each application that uses the value. Also, when using ‘REG_EXPAND_SZ’ and ‘%’ characters in Reg's command line, it is necessary to use escape characters with ‘^’ or overlay notations like ‘%%’ (batch file only) to avoid being interpreted as the ‘%’ character that can be used in command lines/batch files. (Please also note that the ‘^’ character does not work within ‘" "’.)
*2: When specifying a value, if the length is odd, such as ‘12ABC’, it is considered as adding "0" to the beginning (‘012ABC’) and converting it into binary data.
*3: It is used as the type of the value ‘SymbolicLinkValue’ that a key created with ‘REG_OPTION_CREATE_LINK’ possesses. The value of ‘SymbolicLinkValue’ is specified as a Unicode string (UTF-16LE) with an absolute path starting from, for example, ‘\REGISTRY\MACHINE’.
*4: In Reg, the character ‘\0’ (two characters, ‘\’ and ‘0’, as one delimiter) is used as the delimiter. However, it is possible to use a different delimiter by specifying options in each command.
*5: There is a possibility of a crash when attempting to display the details of these values in the Registry Editor.