Windows Registry

The kernel, device drivers, services, Security Accounts Manager, and user interfaces can all use the registry.

By contrast, the Windows Registry stores all application settings in one logical repository (but a number of discrete files) and in a standardized form.

Where changes are made to .INI files, such race conditions can result in inconsistent data that does not match either attempted update.

Keys are referenced with a syntax similar to Windows' path names, using backslashes to indicate levels of hierarchy.

[6] For compatibility with the previous behavior, each registry key may have a "default" value, whose name is the empty string.

The standard types are:[7] The keys at the root level of the hierarchical database are generally named by their Windows API definitions, which all begin with "HKEY".

[11] The key located by HKLM is actually not stored on disk, but maintained in memory by the system kernel in order to map all the other subkeys.

On Windows NT, this key contains four subkeys, "SAM", "SECURITY", "SYSTEM", and "SOFTWARE", that are loaded at boot time within their respective files located in the %SystemRoot%\System32\config\ folder.

A fifth subkey, "HARDWARE", is volatile and is created dynamically, and as such is not stored in a file (it exposes a view of all the currently detected Plug-and-Play devices).

On Windows Vista and above, a sixth and seventh subkey, "COMPONENTS" and "BCD", are mapped in memory by the kernel on-demand and loaded from %SystemRoot%\System32\config\COMPONENTS or from boot configuration data, \boot\BCD on the system partition.

In addition, the %SystemRoot%\Repair folder contains a copy of the system's registry hives that were created after installation and the first successful startup of Windows.

Such rules can filter on properties such as computer vendor name, CPU architecture, installed software, or networks connected to.

The policy is edited through a number of administrative templates which provides a user interface for picking and changing settings.

[28] Also like the file system, PowerShell uses the concept of a current location which defines the context on which commands by default operate.

By using the Set-Location (or the alias cd) command the user can change the current location to another key of the registry.

[30] List of registry API functions: Many programming languages offer built-in runtime library functions or classes that wrap the underlying Windows APIs and thereby enable programs to store settings in the registry (e.g. Microsoft.Win32.Registry in VB.NET and C#, or TRegistry in Delphi and Free Pascal).

Another way is to use the Windows Resource Kit Tool, Reg.exe by executing it from code,[31] although this is considered poor programming practice.

The offreg.dll[33] available from the Windows Driver Kit offers a set of APIs for the creation and manipulation of currently not loaded registry hives similar to those provided by advapi32.dll.

It is also possible to edit the registry (hives) of an offline system from Windows PE or Linux (in the latter case using open source tools).

Prior to the introduction of registration-free COM, developers were encouraged to add initialization code to in-process and out-of-process binaries to perform the registry configuration required for that object to work.

For in-process binaries such as .DLL and .OCX files, the modules typically exported a function called DllInstall()[34] that could be called by installation programs or invoked manually with utilities like Regsvr32.exe;[35] out-of-process binaries typically support the commandline arguments /Regserver and /Unregserver that created or deleted the required registry settings.

[36] COM applications that break because of DLL Hell issues can commonly be repaired with RegSvr32.exe or the /RegServer switch without having to re-invoke installation programs.

[37] Windows exposes APIs that allows user-mode applications to register to receive a notification event if a particular registry key is changed.

[43] Special ACEs on the security descriptor can also implement mandatory integrity control for the registry key and subkeys.

The policy file allows administrators to prevent non-administrator users from changing registry settings like, for instance, the security level of Internet Explorer and the desktop background wallpaper.

To do that the policy file merges into the registry, preventing users from circumventing it by simply changing back the settings.

Windows NT kernels support redirection of INI file-related APIs into a virtual file in a registry location such as HKEY_CURRENT_USER using a feature called "InifileMapping".

For example, Internet Explorer 7 or 8 running in "Protected Mode" on Windows Vista and above will automatically redirect registry writes by ActiveX controls to a sandboxed location in order to frustrate some classes of security exploits.

Current versions of Windows use two levels of log files to ensure integrity even in the case of power failure or similar catastrophic events during database updates.

[55] Even in the case of a non-recoverable error, Windows can repair or re-initialize damaged registry entries during system boot.

Using PowerShell to navigate the registry