Sub topic 20
Registry Editor: hives, keys, and safe editing
This chapter assumes you can open Windows administrative tools, know the difference between an administrator and a standard user, and have read the chapters on System Configuration and System Information. You should also know what a service and a startup program are.
What the registry is
The registry is a hierarchical database where Windows and many applications store configuration settings. Windows reads it at boot, at user sign-in, and whenever a program asks for a setting. Registry Editor (regedit.exe) is the built-in tool for viewing and changing it. Open it with Win+R, type regedit, and approve the User Account Control (UAC) prompt.
On the exam, treat the registry as the place where settings that have no graphical option live, and as a place where a wrong edit can stop Windows from starting.
Hives, keys, values, and data
The registry has a tree structure. Each part has a name:
- A hive is a top-level branch of the tree that is stored in its own set of files on disk.
- A key is a folder inside a hive. Keys can contain other keys, called subkeys.
- A value is a named item stored inside a key. Each value has a type and holds data.
Regedit shows five root keys. Two of them are the real storage, and the other three are shortcuts into them.
| Root key | Abbreviation | What it holds |
|---|---|---|
| HKEY_LOCAL_MACHINE | HKLM | Settings for the whole computer and all users |
| HKEY_USERS | HKU | Settings for every loaded user profile |
| HKEY_CURRENT_USER | HKCU | Settings for the signed-in user (a link to that user's section of HKU) |
| HKEY_CLASSES_ROOT | HKCR | File type associations and COM registration (a merged view of HKLM and HKCU software classes) |
| HKEY_CURRENT_CONFIG | HKCC | The hardware profile currently in use (a link into HKLM) |
The difference between HKLM and HKCU matters in practice. A change under HKLM affects every user and usually needs administrator rights. A change under HKCU affects only the current user. If a problem occurs for one user but not another on the same PC, suspect HKCU or that user's profile.
The files behind the hives are stored in C:\Windows\System32\config for system hives, and each user's NTUSER.DAT file in the profile folder holds that user's HKCU data.
Value types
The exam can ask you to recognize the common value types.
| Type | Meaning | Typical use |
|---|---|---|
| REG_SZ | A text string | Paths, names |
| REG_DWORD | A 32-bit number | On/off flags (0 or 1), timeouts |
| REG_QWORD | A 64-bit number | Large numeric values |
| REG_BINARY | Raw bytes | Hardware data |
| REG_MULTI_SZ | A list of strings | Multi-line settings |
| REG_EXPAND_SZ | A string with environment variables such as `%SystemRoot%` | Paths that vary by system |
Where common settings live
A few keys come up often in support work:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Runlists programs that start for every user at sign-in. The same path under HKCU runs programs for one user only.HKLM\SYSTEM\CurrentControlSet\Servicesholds one subkey per service. TheStartvalue there controls the startup type (2 is automatic, 3 is manual, 4 is disabled).HKLM\SOFTWAREholds machine-wide application settings.
The Run keys are a common place for unwanted programs to hide, so checking them is a standard step when you clean up malware or slow startups.
Editing safely
Treat every edit as something you must be able to undo. Follow this routine.
- Know why you are editing. Find a documented fix from Microsoft or the software vendor. Do not copy random changes from forums.
- Back up first. Create a restore point and export the key you will change.
- Change one thing at a time, and note the old value.
- Test. Sign out, restart, or restart the affected service as needed.
- Revert if it fails. Import the exported file or set the old value back.
To export a key in Regedit, right-click it and choose Export. This saves a .reg file. Double-clicking a .reg file merges its contents back into the registry, which restores the saved values. Keep in mind that a merge adds and overwrites values but does not remove values that were added later.
The same backup can be made from the command line:
reg export "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" C:\Backup\run-hklm.reg
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
reg import C:\Backup\run-hklm.regThe first command saves the key to a file, the second lists its values, and the third restores from the file. Run these in an elevated Command Prompt when you work under HKLM.
Common errors
- Access denied. You are not elevated, or the key is protected by permissions. Reopen Regedit as an administrator. Some keys are owned by the system, and changing their permissions is rarely the right fix.
- Editing the wrong hive. Changing HKCU when the setting needed HKLM (or the reverse) makes the fix appear to have no effect, or to affect only one user.
- Wrong value type. Entering text in a REGDWORD or creating REGSZ where REG_DWORD is required makes the setting be ignored.
- No restart. Some settings are read only at boot or sign-in, so they have no effect until then.
- Importing an untrusted
.regfile. A.regfile can change anything the signed-in account is allowed to change. Open it in a text editor and read it first.
Exercise
A user reports that an unwanted program launches every time any user signs in to a shared PC. You suspect a registry entry. Which key do you check, and what should you do before you delete anything?
Show answer
Check HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run, because entries under HKLM apply to all users (HKCU's Run key affects only one user). Before deleting the value, export the key to a .reg file or create a restore point so you can undo the change.
Exercise
You export a registry key to a .reg file, make several changes, and then double-click the file to restore it. Which of your changes does the restore undo?
Show answer
It overwrites values that exist in the file with their saved data, which undoes edits to those values. It does not remove values or subkeys you added after the export, because a merge only adds and overwrites.