Store application-specific data as common to all users or machine-specific

Store application-specific data as common to all users or machine-specific

Benefits

Description

In the past, most application settings unrelated to the user were placed in HKEY_LOCAL_MACHINE without much further thought given as to whether those settings should be administrable, or stored at all if they don't vary from the defaults. Furthermore, application data that was in reality common to all users of an application (such as a dictionary) may have been installed locally into every user's individual profile.

Nowadays, it is important that your application distinguishes between data that is specific to hardware on the local machine, application settings that apply to all users of an application, and large data common to all users of the application.

In many cases, it’s a better idea to use polices for global values so the administrator can set defaults from a central location,and deploy those policies rather than having to work on a machine by machine basis.

If you must use machine specific settings, then they should be placed in HKEY_LOCAL_MACHINE\Software\CompanyName\Application\Version. Version is optional, but does make upgrades a lot easier. Take care over the size of the data you place in the registry. If your program has combined settings that exceed 100k, store the settings in a settings file in CSIDL_COMMON_APPDATA. The same tradeoffs apply to using settings files that apply to storing defaults in HKEY_LOCAL_MACHINE, it creates more work for administrators and your settings don’t roam.

Put application data files that all users of your program need into CSIDL_COMMON_APPDATA. Actually, you should put your files into a sub-folder by appending CompanyName\ApplicationName\Version to the end of the CSIDL_COMMON_APPDATA path.

Files installed in CSIDL_COMMON_APPDATA (and its sub-folders) are typically placed here at install time, often because users and your program may not have write access at other times. A typical example would be a common spelling checker dictionary.

Considerations

Appending Version number to the CSIDL_COMMON_APPDATA path is optional, but is always a good idea to help better handle upgrades.

Avoid cluttering the registry with default settings.

Try to keep combined registry setting below 100k.

HKEY_LOCAL_MACHINE doesn’t roam. If you need roaming, use policies.

See Also

CSIDLs, Registry Overview, SHGetFolderPath