Windows Registry Files

This document describes the structure of registry files (.reg files) and how they are used to modify the Windows Registry.

Contents

General

Regedit.exe uses registry files (.reg files) to import or export keys and values to the Windows Registry. When a registry file is imported, its contents are imported into the Windows Registry of the local computer. The import can be performed by double-clicking the file or using "Merge" in the Explorer context menu.

Suppressing notification messages during import

In a script, it can be useful to prevent the notification messages from being displayed when importing registry files. The "/s" command-line parameter can be used to disable all notification messages. The script requires administrator privileges to modify the registry.

regedit.exe /s Path\Filename.reg

Structure of a registry file

RegistryEditorVersion

[Pfad\Key1]
"Name1"="Value"
"Name2"="DataType:Value"

[Pfad\Key2]
@="DefaultValue"
"Name3"="DataType:Value"

The first line specifies either "Windows Registry Editor Version 5.00" for Windows 2000 and higher or "REGEDIT4" for Windows 98 and Windows NT 4.0. The "REGEDIT4" header is also supported by newer versions of Windows.

Blank lines should be inserted before each key or subkey to make the file more concise and easier to read.

The key path must be specified in square brackets. A backslash (\) is used to separate each key in the path. For example:

[HKEY_CURRENT_USER\SOFTWARE\Classes\*\shellex\ContextMenuHandlers]

Multiple registry paths can be specified in a registry file. If the lowest key in the path hierarchy is not present in the registry, it will be created. The contents of the registry file will be entered into the registry in the order in which they were specified. If a subkey is to be created within another subkey, they must be specified in the correct order.

[HKEY_CURRENT_USER\SOFTWARE\SubKey1]

[HKEY_CURRENT_USER\SOFTWARE\SubKey1\SubKey2]

The value name begins at the beginning of a value to be imported. This name must be enclosed in double quotation marks. If a value does not yet exist in the registry, it will be created automatically. If the value already exists, the existing value will be overwritten. To set the default value of the key, an @ sign must be specified as the value name. An equal sign (=) follows directly after the value name.

The value follows the equal sign. If the value contains a normal character string (REG_SZ), it is enclosed in double quotation marks. The data type is not specified separately. If it is a different data type, it must precede the actual value, separated by a colon.

Data type in the registry fileData type in the Windows APIDescription
hexREG_BINARYBinary data (identical to hex(3))
dwordREG_DWORDUnsigned 32-bit integer as little-endian (identical to hex(4))
hex(0)REG_NONENo data type
hex(1)REG_SZNull-terminated UTF-16LE string
hex(2)REG_EXPAND_SZNull-terminated UTF-16LE string which may contain environment variables.
hex(3)REG_BINARYBinary data
hex(4)REG_DWORD_LITTLE_ENDIANUnsigned 32-bit integer as little-endian
hex(5)REG_DWORD_BIG_ENDIANUnsigned 32-bit integer as big-endian
hex(6)REG_LINK
hex(7)REG_MULTI_SZMultiple non-empty null-terminated UTF-16LE strings terminated with an additional null character
hex(8)REG_RESOURCE_LIST
hex(9)REG_FULL_RESOURCE_DESCRIPTOR
hex(a)REG_RESOURCE_REQUIREMENTS_LIST
hex(b)REG_QWORD_LITTLE_ENDIAN8 bytes as hexadecimal values, representing a 64-bit integer as little-endian

For binary and quad-word values, the value must be specified in hexadecimal notation. The individual bytes are separated by a comma. Long values can be split into multiple lines. To do so, a backslash must be specified at the end of the line. The next line is indented with two spaces.

Examples of different data types:
@="DefaultValue"
"Binärwert"=hex:00,01,02,03,04,05,06,07
"Text"="Value1"
"DWord-Zahl"=dword:0000007b
"QWord-Zahl"=hex(b):d2,02,96,49,00,00,00,00
"Text-Expand"=hex(2):54,00,65,00,73,00,74,00,2d,00,54,00,65,00,78,00,74,\
  00,00,00
"Text-Multi"=hex(7):54,00,65,00,73,00,74,00,00,00,54,00,65,00,78,00,74,\
  00,00,00,00,00

A registry file should contain a blank line at the end.

Even though some of these requirements aren't mandatory under Windows 10, they should still be observed for compatibility reasons. This applies, for example, to the need for blank lines and the specification of all keys in the hierarchy of subkeys to be created.

Were the free content on my website helpful for you?
Support the further free publication with a donation via PayPal.

Read more about support options...

Creating and editing registry files

Before making any changes to the Windows Registry, at least the relevant key should be exported to restore its original state. This can be done via the main menu "File" / "Export" or via the key's context menu. If the changes cause problems, the backup can be imported back into the registry.

Adding subkeys or values, changing values

The easiest way is to make the relevant changes in the Registry Editor. The relevant key can then be exported to a registry file. Unnecessary keys or values can be removed from the registry file using a text editor.

Deleting keys or values

To delete a key, a minus sign (-) must be placed before the path. To delete a value, a minus sign (-) must be placed after the equal sign.

The following example deletes the key "HKEY_LOCAL_MACHINE\Software\MyOldApplication" and the value "Version" from the key "HKEY_LOCAL_MACHINE\Software\MyOldApplication".

[-HKEY_LOCAL_MACHINE\Software\MyOldApplication]

[HKEY_LOCAL_MACHINE\Software\MyApplication]
"Version"=-

As with changing values, the relevant key can be exported beforehand. The minus sign can then be easily inserted using a text editor.

Renaming Keys or Values

There is no direct way to rename keys and values.

Exporting the existing keys and values saves them. Using a text editor, copy the relevant keys and values, insert them before the saved data, and add a minus sign to delete them. The names of the keys and values are then renamed in the lower part.

Example:

[HKEY_CURRENT_USER\SOFTWARE\TEST]
"Test"="123"

[HKEY_CURRENT_USER\SOFTWARE\MyApplication]
"Version"="1"
"Year"="2022"

The "TEST" key should be changed to "TestApplication" and the "Year" value in the "MyApplication" key to "RegYear". After editing the registry file, it will look like this:

[-HKEY_CURRENT_USER\SOFTWARE\TEST]

[HKEY_CURRENT_USER\SOFTWARE\TestApplication]
"Test"="123"

[HKEY_CURRENT_USER\SOFTWARE\MyApplication]
"Year"=-

[HKEY_CURRENT_USER\SOFTWARE\MyApplication]
"RegYear"="2022"

The "TEST" key is deleted, and the "TestApplication" key is created with the same content. In the "MyApplication" key, the "Year" value is deleted and then recreated with the name "RegYear".

Were the free content on my website helpful for you?
Support the further free publication with a donation via PayPal.

Read more about support options...