简体   繁体   English

将全局应用程序数据放在Vista中的位置?

[英]Where to put global application data in Vista?

Where in a Windows (Vista) system should I place data that ought to be readable and writable by everyone, ie every user of the computer? 在Windows(Vista)的系统应该在哪里我被大家的计算机,即每个用户地方,应该是可读的数据读写的,? Vista's concepts of C:\\Users\\xxx\\AppData\\something, C:\\Program Files and C:\\ProgramData directories and UAC are a bit confusing. Vista的C:\\ Users \\ xxx \\ AppData \\ something,C:\\ Program Files和C:\\ ProgramData目录和UAC的概念有点令人困惑。

Furthermore, is there any ready solution to determine those locations with Java? 此外,有没有现成的解决方案来确定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. 我想它需要与本机库进行一些交互,因为System.getProperties只有user.home和user.dir,它们都不是全局可写的。

In vista c:\\ProgramData is the place, this replaces what used to be C:\\Documents and Settings\\AllUsers\\AppData in XP. 在vista c:\\ ProgramData就是这个地方,它取代了以前用于C:\\ Documents and Settings \\ AllUsers \\ AppData的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. 我不确定在java中执行此操作的具体细节..但是,ALLUSERSPROFILE环境变量为您提供了路径,如果您可以掌握它。 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? 看到这篇文章: 在哪里放置常见的可写应用程序文件?

Unless the data is really large, you might want to take a look at the Preferences API ; 除非数据非常大,否则您可能需要查看Preferences API ; in particular Preferences.systemNodeForPackage . 特别是Preferences.systemNodeForPackage This gives you a platform-independent, system-wide, backend-agnostic storage facility, if that's what you're after. 这为您提供了一个独立于平台的,系统范围的,与后端无关的存储设施,如果这就是您所追求的。

Furthermore, is there any ready solution to determine those locations with Java? 此外,有没有现成的解决方案来确定Java的位置?

You can check approrpirate environment variables, for instance %PROGRAMDATA%, %PROGRAMFILES% and others. 您可以检查适当的环境变量,例如%PROGRAMDATA%,%PROGRAMFILES%等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM