Windows applications: storing your data in the correct place (Roaming, Local, LocalLow, not Documents)
Posted by jpluimers on 2022/03/02
This is a follow on the below TomTom HOME complaint: Know where your application should store its data.
I know this can be tough, especially for applications that were developed before Windows Vista came around: that’s when CSIDL were introduced. But still: Windows XP already had %APPDATA%
(the environment variable equivalent to CSIDL_APPDATA
, it pointed to %USERPROFILE%\\Application Data
)
Applications should store data under either of below locations. Values are KNOWNFOLDERID
constants with CSIDL
constants in parenthesis where available. Some have .NET equivalents in the System.Environment.SpecialFolder
enumeration:
FOLDERID_LocalAppData
(CSIDL_LOCAL_APPDATA
)
The file system directory that serves as a data repository for local (nonroaming) applications.
FOLDERID_LocalAppDataLow
(n/a)
The file system directory that serves as a data repository for local (nonroaming) applications that run under “low integrity” (like in a web browser).
FOLDERID_RoamingAppData
(CSIDL_APPDATA
)
The file system directory that serves as a common repository for application-specific data.
Do not use FOLDERID_Documents
(CSIDL_MYDOCUMENTS
) as this is specific to user documents, not application data.
The virtual folder that represents the
My Documents
desktop item. This value is equivalent toCSIDL_PERSONAL
.
Basically use FOLDERID_LocalAppData for data that is machine specific and FOLDERID_RoamingAppData for data that should travel to other machines when the user logs on to them.
Be very careful how much you store as potentially roamed data as these can go over slow networks (both low bandwidth and low latency).
Documentation
- Deprecated: [Wayback] CSIDL (Shlobj.h) – Win32 apps | Microsoft Docs
CSIDL (constant special item ID list) values provide a unique system-independent way to identify special folders used frequently by applications, but which may not have the same name or location on any given system.
- Current: [Wayback] KNOWNFOLDERID (Knownfolders.h) – Win32 apps | Microsoft Docs
The KNOWNFOLDERID constants represent GUIDs that identify standard folders registered with the system as Known Folders. These folders are installed with Windows Vista and later operating systems, and a computer will have only folders appropriate to it installed. For descriptions of these folders, see CSIDL.
- Reason for change: [Wayback] Known Folders – Win32 apps | Microsoft Docs
Windows Vista introduces new storage scenarios and a new user profile namespace. To address these new factors, the older system of referring to standard folders by a CSIDL value has been replaced. As of Windows Vista, those folders are referenced by a new set of GUID values called Known Folder IDs.
The Known Folder system provides these advantages:
- Independent software vendors (ISVs) can extend the set of Known Folder IDs with their own. They can define folders, give them IDs, and register them with the system. CSIDL values could not be extended.
- All Known Folders on a system can be enumerated. No API provided this functionality for CSIDL values. See IKnownFolderManager::GetFolderIds for more information.
- A known folder added by an ISV can add custom properties that allow it to explain its purpose and intended use.
- Many known folders can be redirected to new locations, including network locations. Under the CSIDL system, only the My Documents folder could be redirected.
- Known folders can have custom handlers for use during creation or deletion.
The CSIDL system and APIs that make use of CSIDL values are still supported for compatibility. However, it is not recommended to use them in any new development.
TomTom HOME Complaint
The complaint: [Wayback] Thread by @jpluimers: Who at @TomTom thought it was a smart idea to store everything TomTom HOME related on Windows under %USERPROFILE%\Documents
Who at @TomTom thought it was a smart idea to store everything TomTom HOME related on Windows under
%USERPROFILE%\Documents
filling up document storage (especially hard when you have a cloud backup!) with some 100 gigabytes.It should have been at level
%LOCALAPPDATA%
at best.
A friend asked me to help figure out why his cloud storage ran out of space.TOMTOM used 99% of his document storage space. These are not even documents at all: just map data either downloaded or from the device.
%LOCALAPPDATA%
or even better%USERPROFILE%\AppData\LocalLow
You should get your Windows developers acquainted toCSIDL
andKNOWNFOLDERID
.CSIDL is deprecated but usually has better descriptions of the values than
KNOWNFOLDERID
: docs.microsoft.com/en-gb/windows/win32/shell/csidlUse
FOLDERID_LocalAppDataLow
orFOLDERID_LocalAppData
, notFOLDERID_AppDataDocuments
KNOWNFOLDERID
documentation is at docs.microsoft.com/en-us/windows/win32/shell/knownfolderid and points to the correspondingCSIDL
values, if any.In addition, newer versions of TomTom HOME should migrate old data to the correct locations.
I know that’s hard, but software development is.
The above is the unwrap of four tweets.
Related
- My blog:
NTUSER.INI
– sets what parts of your Windows profile are roaming.- InnoSetup where the *AppData constants point to
- Windows: Where is my DropBox configuration? (DropBox used to default to
%APPDATA%
for everything, causing trouble with roaming profiles; I’m not sure what the current version does as it has become bloatware). - Outlook signature locations (note that various versions of Windows use different versions of profile name, appending an extension like nothing at all,
.V2
or.V6
) - (Roaming) Profile and Folder Redirection
- [Wayback] windows – Why are there directories called Local, LocalLow, and Roaming under \Users\\AppData? – Super User which mentions the below roaming document and links to these about integrity levels:
- [Wayback] Managing Roaming User Data Deployment Guide | Microsoft Docs: still the goto document for fundamentals of roaming profiles.
- Also available as archived word document: [Wayback: http://download.microsoft.com/download/3/b/a/3ba6d659-6e39-4cd7-b3a2-9c96482f5353/Managing%20Roaming%20User%20Data%20Deployment%20Guide.doc]
- [Wayback] Include and exclude folders in roaming user profiles | 4sysops
A Group Policy Object (GPO) has always allowed administrators to exclude folders from a roaming profile but not include them. I’d always assumed that the functionality of a roaming profile was more or less hardcoded, whereby it only captured data from AppData\Roaming. However, I have to admit I was mistaken, and I give big thanks to Raphael Schulz for pointing this out to me.
- [Wayback] Appdata\Local and LocalLow following roaming profile??
- [Wayback] Beware of roaming user profiles | The Old New Thing (roaming profiles and data has been a tough thing since the Windows NT 4 days)
–jeroen
Leave a Reply