Last modified on 21 October 2010, at 13:14

Windows Programming/Registry API

The RegistryEdit

The registry is a system-defined hierarchical central database in x86, x64 and Mobile versions of Microsoft Windows System. The Windows Registry API provides methods for an application to save and query data stored in the registry. Although the registry was present even in 3.x Windows, it was used to store much less data.

The registry stores configuration settings for software, information about operating system configuration, current hardware profile, drivers' settings etc. It was also designed to replace the old-fashioned way of storing application data in .ini files. On 16-bits Windows systems applications used to store data in configuration files with .ini extensions.

Values are grouped and stored in keys. The registry stores keys in tree format, with keys containing values and sub-keys.

Applications should only modify keys created by itself, and changing or deleting other application's keys and values is not recommended. Also, an application shouldn't modify keys containing important system settings. We should keep these two tips in mind when editing registry (of course there are situations when we want to change some system settings but this is very rare).

Opening a KeyEdit

Keys must be opened before they can be used. To do this, we use either of

RegOpenKeyEx() 
To open any key.
RegCreateKeyEx() 
To create a key or open it if it exists already.

ValuesEdit

The value of a key can be obtained by calling RegQueryValueEx().

The RegSetValueEx() function is used to associate a value with a key.

Key HierarchyEdit

Next ChapterEdit