Vista 中全局应用程序数据放在哪里?
我应该在 Windows (Vista) 系统中的哪个位置放置每个人(即计算机的每个用户)都应该可读和可写的数据? Vista的C:\Users\xxx\AppData\something、C:\Program Files和C:\ProgramData目录以及UAC的概念有点混乱。
此外,有没有现成的解决方案可以用Java确定这些位置? 我认为它需要与本机库进行一些交互,因为 System.getProperties 只有 user.home 和 user.dir,两者都不是全局可写的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 vista 中,c:\ProgramData 是这个位置,它取代了 XP 中原来的 C:\Documents and Settings\AllUsers\AppData。
我不确定在 java 中执行此操作的具体细节。但是,如果您能掌握该路径,则 ALLUSERSPROFILE 环境变量会为您提供路径。 您应该始终使用此选项,而不是对路径进行硬编码,因为文件夹名称会在不同国际化版本的操作系统上发生变化。
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.
如果您需要允许没有管理员权限的用户修改全局设置,那么正确的方法是为应用程序创建一个安装程序,并在安装过程中设置“通用应用程序数据”文件夹的权限,以便允许用户区域写信给它。
请参阅这篇文章:在哪里放置常见的可写应用程序文件?
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: Where to put common writable application files?
除非数据非常大,否则您可能需要查看 首选项 API; 特别是
Preferences.systemNodeForPackage
。 这为您提供了一个独立于平台、系统范围、与后端无关的存储设施(如果这就是您所追求的)。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.您可以检查适当的环境变量,例如%PROGRAMDATA%,%PROGRAMFILES%等。
You can check approrpirate environment variables, for instance %PROGRAMDATA%, %PROGRAMFILES% and others.