Differences in %ALLUSERSPROFILE% in Windows XP and Vista+

Is there an environment variable in Windows that indicates the folder to store application data that is shared by all users? In Windows Vista and later, this is %ALLUSERSPROFILE% (typically maps to C:/ProgramData ). However in Windows XP, %ALLUSERSPROFILE% maps to C:\Documents and Settings\All Users and I would still need to add something like \Program Data\ to get to the equivalent location.

asked May 17, 2016 at 7:08 Grodriguez Grodriguez 22k 10 10 gold badges 68 68 silver badges 116 116 bronze badges

Not entirely helpful in solving your particular problem, but the pragmatic solution would be to ask your customers to upgrade to a supported version of the OS.

Commented May 17, 2016 at 8:13 Please add a language tag so we know which language you are programming in. Commented Jan 1, 2017 at 1:09

@Anders The question is not language-specific. I am aware there are APIs to achieve the same thing without resorting to environment vars, but I specifically wanted to know about environment vars.

Commented Jan 3, 2017 at 9:06

1 Answer 1

I don't know of a good solution for batch-files but I can explain the history.

On Windows 2000/XP/2003 %ALLUSERSPROFILE% is exactly what its name is, the root of the all-users/shared/common profile directory. Typically "C:\Documents and Settings\All Users".

The Windows shell has a special folder constant called CSIDL_COMMON_APPDATA and it typically resolves to "C:\Documents and Settings\All Users\Application Data" but there is unfortunately no environment variable set for this path on these systems.

In Windows Vista and later the documents, music and video folders were moved out of the %ALLUSERSPROFILE% folder and placed in a new folder called Public ("c:\Users\Public") and can be found with %PUBLIC% . CSIDL_COMMON_APPDATA also got a environment variable called %ProgramData% and because most of the other folders moved to %PUBLIC% it was decided that %ALLUSERSPROFILE% did not need the Application Data subfolder so %ProgramData% is the same as %ALLUSERSPROFILE% .

If you are writing a batch-file:

My suggestion is, use %ProgramData% if it exists, otherwise, fall back to %ALLUSERSPROFILE%\Application Data . I don't know if the Application Data folder has a different name on localized versions of Windows.

If you are writing a C/C++ application:

If you are writing a .NET application: