Sorry for being really ignorant here, I just want to learn, why is the registry needed for programs? What's it for and why can't software just write variables to their own local files? Does it do something I'm not aware of?
Central, ubiquitous management of program preferences and settings.
It's just a silly convention. In a unix or mac filesystem the software does exactly what you suggest, writing its settings in normal files, usually organized in hidden folders in the user's home directory. Windows has something similar, a folder called "Application Data" off of each user's home folder, and your program can use that for storage instead of screwing with windows APIs and the registry.
Actually, that was the way it was done in Windows 3.1, with many applications using their own INI files. Windows 95 (from memory) introduced the concept of a centralised repository (though I think there was a limited purpose registry before then) and people have been buying registry cleaner programs ever since.
People used to complain then that there were too many INI files to manage and that speed was a problem since they were text files that needed parsing. I, for one, prefer applications to have their own stuff in their own directories so as to make clean-up easier when you want to delete them.
Registry Purpose
The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low-level operating system components as well as the applications running on the platform: the kernel, device drivers, services, SAM, user interface and third party applications all make use of the Registry. The registry also provides a means to access counters for profiling system performance.
Why Registry over INI files?
.INI files stored each program's user settings in a separate file. By contrast, the Windows registry stores all application settings in one central repository and in a standardized form. This offers several advantages over INI files.[2] Since accessing the registry does not require parsing, it may be read from or written to more quickly than an INI file. As well, strongly-typed data can be stored in the registry, as opposed to the text information stored in INI files. Because user-based registry settings are loaded from a user-specific path rather than from a read-only system location, the registry allows multiple users to share the same machine, and also allows programs to work for a least-privilege user. Backup and restoration is also simplified as the registry can be accessed over a network connection for remote management/support, including from scripts, using the standard set of APIs, as long as the Remote Registry service is running and firewall rules permit this.
The registry has features that improve system integrity, as the registry is constructed as a database and offers database-like features such as atomic updates. If two processes attempt to update the same registry value at the same time, one process's change will precede the other's and the overall consistency of the data will be maintained. Where changes are made to INI files, such race conditions can result in inconsistent data which doesn't match either attempted update. Windows Vista and Windows 7 provide transactional updates to the registry, extending the atomicity guarantees across multiple key and/or value changes, with traditional commit-abort semantics. (Note however that NTFS provides such support for the file system as well, so the same guarantees could, in theory, be obtained with traditional configuration files.)
Quoted verbatim from wikipedia:
When first introduced with Windows 3.1, the Windows registry's primary purpose was to store configuration information for COM-based components. With the introduction of Windows 95 and Windows NT, its use was extended to tidy up the profusion of per-program INI files that had previously been used to store configuration settings for Windows programs.
The Windows Registry was intended to stem the proliferation of local .ini
files that programs were writing.
It has been well argued that the particular implementation was far worse than the problem it set out to cure. Having had to do precision surgery on a registry or two in my life, I happen to agree.
Why can't software just write variables to their own local files?
It can, but this can be inconvenient for the software developer, because:
- The developer must write their own parser.
- The developer must write their own serialization logic.
- Users who want to edit options manually must learn the syntax of that given configuration file.
The registry is nothing more than a simple (from a programmer's prospective) database.
IMHO, the Windows Registry is an invention almost as practical and useful as the pet rock.
By putting application configuration data in the same place with operating system configuration data, it makes any attempt to update an app carry the danger of screwing up the operating system. It's like making a single remote control that controls both your television and your pacemaker. Sure, you could argue that it's convenient to have all the controls in one place, but it also creates the danger that any attempt to change the channel will kill you.
The old INI files were easy to read and update by both computers and humans. For the truly lazy programmer who couldn't figure out how to manipulate a simple text file, there were library functions to do it simply and easily. The registry is mildly difficult to update with a program, and extremely difficult for any human being to read, especially a non-programmer.
In the bad old days when each program had a directory and stored all its data in that directory, you could delete a program by simply deleting the directory, and you could confidently back up a program by simply copying this directory. With the registry, you need a special uninstall program for each program, and it is common to have obsolete or junk entries float around in the registry indefinately.
Is there anyone out there who can say with a straight face that the registry is easy to manage, or that it increases the reliability of the system?
What I think Microsoft should have done was create a central file that recorded the directory where each app is installed and the extensions of files that it knows how to open. That should be the only information the OS needs to know about an app. Everything else should be stored in the app's own directory.