The Windows Registry
The Windows Architecture Deep Dive · Windows Programming track
10 min read
In this module
The Central Configuration Database
The Windows Registry is a hierarchical database holding configuration for the OS, hardware, drivers, services, and applications. Where Linux scatters text config files across the filesystem, Windows funnels almost everything into one place. If you do system administration, troubleshooting, or security analysis on Windows, you live in the registry whether you like it or not.
Registry Structure
The registry is a tree of keys (think directories) and values (think files). Each value carries a name, a type, and some data.
Root Keys (Hives)
The registry has five root keys, each backed by a different data source:
Hive Files on Disk
Each hive is stored as a binary file on disk:
C:\Windows\System32\config\├── SYSTEM ← HKLM\SYSTEM├── SOFTWARE ← HKLM\SOFTWARE├── SAM ← HKLM\SAM├── SECURITY ← HKLM\SECURITY├── DEFAULT ← HKU\.DEFAULT├── SYSTEM.LOG1 ← Transaction log├── SYSTEM.LOG2 ← Transaction log (backup)├── SOFTWARE.LOG1└── ...
C:\Users\<username>\└── NTUSER.DAT ← HKCU for that userThese files stay locked while Windows is running. Touching them directly means booting into another OS or a recovery environment first.
A hive file opens with a 4 KB base block — a header carrying the "regf" signature, timestamps, and checksums. After that, the file splits into bins of at least 4 KB, and each bin holds cells. A cell can be a key node, value node, subkey list, value list, or security descriptor; free cells are tracked so they can be reused. The format is documented, and every serious forensic tool speaks it.
Value Types
Registry values can hold different data types:
| Type Name | Code | Description |
|---|---|---|
| REG_NONE | 0 | No defined type |
| REG_SZ | 1 | Null-terminated Unicode string |
| REG_EXPAND_SZ | 2 | String with %VARIABLE% refs |
| REG_BINARY | 3 | Raw binary data |
| REG_DWORD | 4 | 32-bit unsigned integer |
| REG_DWORD_BIG_ENDIAN | 5 | 32-bit big-endian (rare) |
| REG_LINK | 6 | Symbolic link to another key |
| REG_MULTI_SZ | 7 | Array of null-terminated strings |
| REG_QWORD | 11 | 64-bit unsigned integer |
Programmatic Access
// Reading a registry valueHKEY hKey;DWORD result = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &hKey);
if (result == ERROR_SUCCESS) { char productName[256]; DWORD size = sizeof(productName); DWORD type; RegQueryValueEx(hKey, "ProductName", NULL, &type, (LPBYTE)productName, &size); // productName = "Windows 10 Pro" (or similar) RegCloseKey(hKey);}
// Writing a registry valueRegCreateKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\MyApp", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
DWORD setting = 1;RegSetValueEx(hKey, "EnableFeature", 0, REG_DWORD, (LPBYTE)&setting, sizeof(setting));RegCloseKey(hKey);Important Registry Locations
Boot and Hardware Configuration
HKLM\SYSTEM\CurrentControlSet\├── Control\│ ├── ComputerName\ ← Machine name│ ├── Session Manager\ ← Boot execute, memory management│ │ ├── BootExecute ← Programs run before login (autochk)│ │ └── Memory Management\ ← Page file config, large pages│ ├── TimeZoneInformation\ ← System timezone│ └── Lsa\ ← Security settings├── Services\ ← All services and drivers│ ├── Tcpip\ ← TCP/IP configuration│ ├── LanmanWorkstation\ ← SMB client│ └── ... (hundreds of services)└── Enum\ ← Hardware enumeration ├── PCI\ ← PCI devices ├── USB\ ← USB devices └── ACPI\ ← ACPI devicesSoftware and Autostart
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\├── Run\ ← Programs that start at logon (all users)├── RunOnce\ ← Run once then delete├── Policies\ ← Group Policy settings└── Explorer\ ← Explorer/shell settings
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\├── Run\ ← Per-user autostart programs├── RunOnce\ ← Per-user run once└── Explorer\ ← Per-user shell settingsAutostart locations are malware's favourite real estate for persistence, which is why every half-decent security tool watches these keys for unsanctioned writes.
Security-Critical Keys
HKLM\SAM\SAM\Domains\Account\Users\└── 000001F4\ ← Administrator account └── V ← Contains password hash data
HKLM\SECURITY\Policy\Secrets\└── (LSA secrets: cached credentials, service account passwords)
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\├── Shell ← Default shell (explorer.exe)├── Userinit ← Programs run at logon└── AutoAdminLogon ← Auto-logon configurationThe registry's autostart locations (Run, RunOnce, Services, Winlogon entries) are the most common places malware installs itself for persistence. Security professionals routinely check these locations during incident response. Tools like Sysinternals Autoruns surface every autostart entry across the registry and file system in one place.
Registry Virtualisation
From Vista onward, registry virtualisation quietly redirects writes that legacy non-UAC-aware applications aim at protected HKLM locations:
Legacy app tries to write: HKLM\SOFTWARE\MyApp\Setting = "value"
Without admin rights, the write is redirected to: HKCU\SOFTWARE\Classes\VirtualStore\MACHINE\SOFTWARE\MyApp\Setting
Subsequent reads check VirtualStore first, then the real location.Old applications that blithely assumed admin rights keep running, none the wiser, without actually touching machine-wide settings.
Transactional Registry (TxR)
Windows Vista introduced the Kernel Transaction Manager (KTM) which supports transactional registry operations:
// Create a transactionHANDLE hTransaction = CreateTransaction(NULL, 0, 0, 0, 0, 0, NULL);
// Open registry key within the transactionHKEY hKey;RegOpenKeyTransacted(HKEY_LOCAL_MACHINE, "SOFTWARE\\MyApp", 0, KEY_WRITE, &hKey, hTransaction, NULL);
// Make changes (not yet visible to other processes)RegSetValueEx(hKey, "Setting1", 0, REG_DWORD, ...);RegSetValueEx(hKey, "Setting2", 0, REG_SZ, ...);
// Commit all changes atomicallyCommitTransaction(hTransaction);// OR rollback:// RollbackTransaction(hTransaction);
CloseHandle(hTransaction);RegCloseKey(hKey);All-or-nothing semantics: either every change in the transaction lands, or none of them do. No half-applied updates leaving the system half-configured. The on-disk transaction logs (.LOG1, .LOG2) are how the registry recovers after a crash.
Registry Internals
Hive Structure
Internally, a hive is organised as:
Each cell has a size field; the sign encodes its state — negative means allocated, positive means free. Key nodes pack in timestamps, a parent pointer, subkey and value counts, and pointers off to the subkey and value lists.
Performance Considerations
The registry lives in paged pool. Hot hives like SYSTEM and SOFTWARE can chew through real memory, so Windows leans on a few tricks:
- Cell indexes stand in for raw pointers, so a hive can be relocated in memory
- Lazy flushing: changes are batched and pushed to disk every few seconds
- Log files: writes hit the log first, then get applied to the primary hive on the next flush
The cell-index trick deserves a picture. A key node never stores "the subkey list lives at address X". It stores a 32-bit cell index, and the configuration manager turns that into an address through a per-hive map every time it follows the link:
Follow the dotted edge: when a block ends up at a different address, only one map-table entry is rewritten. Every cell index stored inside the hive stays valid, and on disk the same index is simply an offset from the first bin.
The registry sits at the heart of Windows. Boot configuration, security policy, application preferences — they're all values in this database. If you do Windows programming, sysadmin, or security work, fluency here pays off constantly.