On Window 7, 8 and 10 I want my app to store data in shared location so all users who run the app on the PC will access the same data. The data are readable/writable. What location should I use?
Asked
Active
Viewed 5,657 times
8
-
Is your app installed in program files directory? If yes, you can use the app's folder to store data. If not, you can use `Program Files\Common Files` folder. – Sнаđошƒаӽ Nov 13 '16 at 14:49
-
@Sнаđошƒаӽ That's not what `Common Files` is for. `Common Files` is nowadays unused, but it's intended for immutable common components shared by multiple (potentially separately installed) applications, such as libraries and utility programs - the canonical example being the (old, pre-2007) Microsoft Equation Editor, which would be installed by separate standalone installations of Word and PowerPoint, for example. – Dai Nov 13 '16 at 14:53
-
@Dai Thanks, didn't know that. I kinda thought `Common Files` was a common *dump* :P. Your answer is very informative. Didn't know all that. ;-) – Sнаđошƒаӽ Nov 13 '16 at 14:55
1 Answers
16
Windows has funny rules regarding program' shared data.
- Program Files ("
C:\Program Files
" and "C:\Program Files (x86)
") is intended for immutable (read-only) program data and executable files - consequently files here require administrative permissions to edit. Thus it makes it useful for important files that should not be compromised (e.g. your main executable). This is why installers run with elevated permissions. There is a downside in that if your program has an auto-update mechanism then that too needs to run elevated. - Program Data (
C:\ProgramData
on Windows Vista and later, orC:\Documents and Settings\All Users\Application Data
) is intended for mutable program data - you don't need administrative permissions to create files in this folder, except that once a file has been created only the user that originally created that file can subsequently edit it (though everyone can read it). This is the specialCREATOR OWNER
permission.- This is described here: Privileges/owner issue when writing in C:\ProgramData\
- AppData (
C:\Users\(you)\AppData\Local
andC:\Users\(you)\AppData\Roaming
) is user-specific and is intended for user-specific settings, configuration and data. TheLocal
version should be used for machine-specific settings that shouldn't roam if the user is using Roaming Profiles, such as data caches (e.g. a browser cache).
So in your case ProgramData
looks ideal, but you need to be careful about the default CREATOR OWNER
rules - but there's a workaround: your program's installer (which would run as admin) has the ability to change the ACL permissions on its ProgramData subdirectory to allow other users to edit files. I suggest granting the Users
group permission instead of Everyone
to prevent possible remote attacks and modifications by unauthenticated users.
-
I am not sure anymore (asked [a question about this](https://stackoverflow.com/questions/61736933/is-there-a-standard-location-for-architecture-independent-shared-program-files-o) yesterday) that `%ProgramData%` is for specifically *mutable* data -- if an installation, which is run by an administrator, creates a folder there, then it is effectively "immutable", even for installed application as most applications are well-behaved now and run without elevated privileges. – Armen Michaeli May 13 '20 at 12:44