Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Registry best practices

In what way is the Windows registry meant to be used? I know it's alright to store a small amount of user preferences, but is it considered bad practice to store all your users data there? I would think it would depend on the data set, so how about for small amounts of data, say, less than 2KB, in 100 or so different key/value pairs. Is this bad practice? Would a flat file or SQLite db be a better practice?

like image 531
Sean Avatar asked Mar 27 '09 21:03

Sean


People also ask

What is the major disadvantage of using registry in Windows?

Windows registry disadvantages are as follows: Transferring per-program user settings between Windows machines is tedious, as the Windows registry is largely dependent on the local machine.

What are the 5 registry keys?

What are the five registry keys? In most versions of Windows, the following keys are in the registry: HKEY_CLASSES_ROOT (HKCR), HKEY_CURRENT_USER (HKCU), HKEY_LOCAL_MACHINE (HKLM), HKEY_USERS (HKU), and HKEY_CURRENT_CONFIG.

When should I use Windows Registry?

The registry helps Windows manage and operate your computer, ensuring access to critical resources and helping important programs configure settings. A hierarchical database structure of keys and values makes up the registry.

Does Windows 10 still use registry?

Windows Registry Availability The Windows Registry and the Microsoft Registry Editor program are available in nearly every Windows version including Windows 11, Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows 2000, Windows NT, Windows 98, and Windows 95.


1 Answers

I'm going to take a contrarian view.

The registry is a fine place to put configuration data of all types. In general it is faster than most configuration files and more reliable (individual operations on the registry are transacted so if your app crashes during a write the registry isn't corrupted - in general that isn't the case with ini files).

Marcelo MD is totally right: Storing things like operation percentage complete in the registry (or any other non volitile storage) is a horrible idea. On the other hand storing data like the most recently used files is just fine - the registry was built for just that kind of problem.

A number of the other commenters on this post talking about the MRU list have discussed the problem of what happens when the MRU list gets out of sync due to application crashes. I'm wondering why storing the MRU list in a flat file in per-user storage is any better?

I'm also not sure what the "security implications" of storing your data in the registry are. The registry is just as secure as the filesystem - the registry and the filesystem use the same ACL mechanism to protect their data.

If you ARE going to store your user data in a file, you should absolutely put your data in %APPDATA%\CompanyName\ApplicationName at least - that way if two different developers create an application with the same name (how many "Media Manager" applications are there out there?) you won't have collisions.

like image 87
ReinstateMonica Larry Osterman Avatar answered Oct 18 '22 13:10

ReinstateMonica Larry Osterman