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.
|
||||||||||||||||||||||||
<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 QUERY
- REG ADD
- REG DELETE
- REG COPY
- REG SAVE
- REG RESTORE
- REG LOAD
- REG UNLOAD
- REG COMPARE
- REG EXPORT
- REG IMPORT
- REG FLAGS
Reg returns the following exit codes, which can be used when branching the process using constructs such as If Errorlevel.
0 | The operation was successful. |
1 | The 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.
-
Name Actual root key Description HKLM HKEY_LOCAL_MACHINE
Primarily contains settings for the entire system. HKCU HKEY_CURRENT_USER
Contains 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
.HKCR HKEY_CLASSES_ROOT
Contains settings used for file associations, COM (Component Object Model), and similar purposes. It combines the contents of HKEY_CURRENT_USER\Software\Classes
andHKEY_LOCAL_MACHINE\Software\Classes
.HKU HKEY_USERS
Contains settings for all users known to the system. HKCC HKEY_CURRENT_CONFIG
Contains 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
, andHKEY_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 name | Numeric value | Meaning | Details |
---|---|---|---|
REG_NONE | 0 | Undefined value | Primarily used when the mere presence of the value itself has significance (not commonly used). |
REG_SZ | 1 | String | Stores a regular string. |
REG_EXPAND_SZ | 2 | Expandable string | You can include the name of an environment variable as a value, like ‘%ENVNAME%’. (*1) |
REG_BINARY | 3 | Binary data | Holds 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 | 4 | 32-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_ENDIAN | 5 | 32-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) | 6 | Link | Used for a value that holds the reference to the destination of a key created for linking purposes. (*3) |
REG_MULTI_SZ | 7 | Multi-line string | Used when holding multiple strings, such as lists or arrays, as a single value. (*4) |
(REG_RESOURCE_LIST) | 8 | List of resources for resource mapping | (Details not investigated; mainly used in hardware/drivers.) (*5) |
(REG_FULL_RESOURCE_DESCRIPTOR) | 9 | List of resources for hardware identifiers | (Details not investigated; mainly used in hardware/drivers.) (*5) |
(REG_RESOURCE_REQUIREMENTS_LIST) | 10 | List of resources for resource mapping | (Details not investigated; mainly used in hardware/drivers.) (*5) |
REG_QWORD | 11 | 64-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.