views:

1030

answers:

4

Where in a Windows (Vista) system should I place data that ought to be readable and writable by everyone, i.e. every user of the computer? Vista's concepts of C:\Users\xxx\AppData\something, C:\Program Files and C:\ProgramData directories and UAC are a bit confusing.

Furthermore, is there any ready solution to determine those locations with Java? I suppose that it requires some interaction with native libraries, since System.getProperties has just user.home and user.dir, neither of which is globally writable.

+5  A: 

In vista c:\ProgramData is the place, this replaces what used to be C:\Documents and Settings\AllUsers\AppData in XP.

I'm not sure about the specifics of doing this in java.. but, the ALLUSERSPROFILE environment variable gives you the path if you can get hold of that. You should always use this instead of hard coding the path, because the folder name changes on different internationalized versions of the OS.

Scott Langham
Thanks! It seems that System.getenv("ALLUSERSPROFILE") gives C:\ProgramData on my system, at least.
Joonas Pulakka
C:\ProgramData requires that the user have administrator permissions to write to. See my post below.
blak3r
+1  A: 

Unless the data is really large, you might want to take a look at the Preferences API; in particular Preferences.systemNodeForPackage. This gives you a platform-independent, system-wide, backend-agnostic storage facility, if that's what you're after.

gustafc
+1  A: 

Furthermore, is there any ready solution to determine those locations with Java?

You can check approrpirate environment variables, for instance %PROGRAMDATA%, %PROGRAMFILES% and others.

majkinetor
+4  A: 

If you need to allow users that do not have administrator privileges to modify the global settings then the proper approach is to create an installer for the application and during the install set the permissions on the "Common Application Data" folder such that users area allowed to write to it.

See this post: http://stackoverflow.com/questions/147016/where-to-put-common-writable-application-files

blak3r