Working with Windows Registry – Part 1
Every Windows user, at some point of time in his interaction with the Windows OS, definitely comes across the term ‘registry’ and might even work on it. However, in most of the cases, user interaction with the Registry occurs in the GUI form (i.e. via the Registry Editor a.k.a. regedit.exe). Here, we shall be working with registry from a programmer’s viewpoint, and the tasks will be performed through code rather than the GUI. Let’s begin with the introduction.
Working with Registry – Introduction
- We access the registry through the registry keys (or keys), which are somewhat similar to the File System directories.
- A key is like a directory. Just as a directory has files & sub-directories inside it, a registry key has values & sub-keys.
- A value is like a file. Just as a file has a name and contains some data, a value also has a name & stores some data.
- A key can contain other keys or key/value pairs.
The registry contains the following types of information concerning the Computer’s hardware, the Windows O.S. and the installed applications :
1. Processor type, number of processors, memory etc.
2. Windows version number, build number and the registered user.
3. Data of various installed applications, like Application Name, Application Creator i.e. Company Name or Developer Name, Version number etc.
4. User-account names, user preferences etc.
5. Mappings from file name extensions to programs. (This feature links a file extension with a program which can open that particular type of file. For example, .docx is linked to Microsoft Word, .wmv is linked with Windows Media Player and so on.)
Components of the Registry
There are FIVE most important keys in the registry. They are the top-level keys and all the other registry keys can be accessed from these FIVE keys. These are listed below :
Working with Registry using Windows API – Video
Registry Management using API functions
There are two categories of functions here :
1. Key Management Functions : These functions are used to create, open, close and delete keys. These functions are listed below :
a) RegCreateKeyEx () – This function creates a new key.
b) RegDeleteKey () – This function deletes an existing key.
c) RegOpenKeyEx () – This function opens an existing key.
d) RegCloseKey () – This function closes an open key handle.
e) RegEnumKeyEx () – This function enumerates (i.e. creates a list of) subkeys of an open registry key. It retrieves the key name, class string, and the time of last modification of each subkey.
2. Value/Data Management Functions : These functions are used to read and set the values of data contained in existing keys. These functions are listed below :
Read How to Backup the Registry before making any changes to your computer’s registry. This article is the first part of the Working with Registry series.