Registry Values
Last updated: October 26, 2023
This section details the various types and representations of values that can be stored within Windows Registry keys.
Registry values are the fundamental pieces of data stored in the Windows Registry. Each value consists of a name, a data type, and the actual data. The data type specifies how the data should be interpreted.
Registry Value Structure
A registry value is defined by the following components:
- Name: A unique string that identifies the value within a key. The default value for a key has an empty string name.
- Type: An integer that specifies the data type of the value.
- Data: The actual data associated with the value, interpreted according to its type.
Common Registry Value Data Types
The Windows Registry supports several predefined data types. Understanding these types is crucial for correctly reading and writing registry values.
Constant Name | Value (Decimal) | Description |
---|---|---|
REG_SZ |
1 | A null-terminated string. |
REG_EXPAND_SZ |
2 | A null-terminated string that contains unexpanded references to environment variables (for example, "%SystemRoot%\MyDll.dll"). The system expands these references when it retrieves the value. |
REG_BINARY |
3 | A binary data in any format. |
REG_DWORD |
4 | A 32-bit unsigned integer. On 64-bit systems, this is a 32-bit value. |
REG_DWORD_LITTLE_ENDIAN |
4 | A 32-bit unsigned integer in little-endian format. This is the same as REG_DWORD . |
REG_DWORD_BIG_ENDIAN |
5 | A 32-bit unsigned integer in big-endian format. |
REG_LINK |
6 | A null-terminated Unicode string that is a symbolic link. The system maintains this value. Applications should not modify it. |
REG_MULTI_SZ |
7 | An array of null-terminated strings, terminated by two null characters. Each string is a separate entry. |
REG_RESOURCE_LIST |
8 | A structure describing the hardware resources allocated for a device. |
REG_FULL_RESOURCE_DESCRIPTOR |
9 | A structure describing the hardware resources for a device. |
REG_RESOURCE_REQUIREMENTS_LIST |
10 | A structure describing the hardware resources required for a device. |
REG_QWORD |
11 | A 64-bit unsigned integer. On 64-bit systems, this is a 64-bit value. |
REG_QWORD_LITTLE_ENDIAN |
11 | A 64-bit unsigned integer in little-endian format. This is the same as REG_QWORD . |
Working with Registry Values
The Winreg API provides functions to create, delete, query, and modify registry values. Key functions include:
RegCreateKeyEx
: Creates or opens a specified key.RegSetValueEx
: Sets the data and type of a specified registry value.RegQueryValueEx
: Retrieves the data and type of a specified registry value.RegDeleteValue
: Deletes a specified registry value.RegEnumKeyEx
: Enumerates the subkeys of a specified key.RegEnumValue
: Enumerates the values of a specified key.
Example: Reading a String Value
The following pseudocode demonstrates how to read a REG_SZ
value:
HKEY hKey;
TCHAR szValueData[MAX_PATH];
DWORD dwBufferSize = MAX_PATH * sizeof(TCHAR);
LONG result;
// Open a key (e.g., HKEY_CURRENT_USER\\Software\\MyApp)
result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\MyApp"), 0, KEY_READ, &hKey);
if (result == ERROR_SUCCESS) {
// Query the value (e.g., "InstallPath")
result = RegQueryValueEx(hKey, TEXT("InstallPath"), NULL, NULL, (LPBYTE)szValueData, &dwBufferSize);
if (result == ERROR_SUCCESS) {
// szValueData now contains the string from the registry
// Process szValueData...
}
RegCloseKey(hKey);
}
Registry Value Limits
While the registry can store a large amount of data, there are practical limits to the size of individual values and the overall registry size. Refer to Microsoft documentation for current limitations.
For more detailed information on specific registry data types and their handling, please refer to the relevant API function documentation.