在 Windows 中是否有任何文件夹可以替代 ProgramData?
我正在编写一个桌面应用程序,需要一个文件夹...
- 存在于 Windows 7 和 Vista 中
- 对于所有用户来说都是通用的(用于存储配置数据)。
- 应用程序可以在其上保存数据,无需管理员权限(不像“ProgramData”)。
- 是标准的(我不想在“C:”、桌面或其他类似位置创建另一个应用程序特定文件夹。)
- 当然,“程序文件”不是一个选项。
您能否建议一个合适的文件夹,或者更好地使用注册表?
I'm writing a desktop app and need a folder which...
- Exists in Windows 7 and Vista
- Is common to all users (for store config data).
- Application can save data on it, without Admin privileges (not like "ProgramData").
- is standard (I don't want to create another app specific folder in "C:", the Desktop or other place alike.)
- "Program Files" is not an option, of course.
Can you suggest an appropriate folder, or better use the Registry?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
建议的方法是在安装时在“ProgramData”下创建一个专用于您的应用程序的文件夹(即
CSIDL_COMMON_APPDATA
/FOLDERID_ProgramData
)。如您所知,
CSIDL_COMMON_APPDATA
文件夹对于标准用户来说是只读的。因此,您的安装程序需要为它创建的文件夹提供允许您所需访问的 ACL。这是满足您要点中列出的所有标准的解决方案。
你提到了注册表。注册表中不存在所有用户共享但标准用户可写入的区域。虽然您可以使用 ACL 授予对注册表更宽松的访问权限,但这实际上还没有完成。请忘记我什至提到过这种可能性!
The recommended way to do this is to create a folder at install time, dedicated to your application, underneath "ProgramData" (i.e.
CSIDL_COMMON_APPDATA
/FOLDERID_ProgramData
).As you already know, the
CSIDL_COMMON_APPDATA
folder is read only for standard users. So your install program needs to give the folder that it creates an ACL that permits the access that you require.This is the solution that meets all the criteria laid out in your bullet points.
You mention the registry. There is no area of the registry that is shared between all users and yet writeable by standard users. Whilst you can use ACLs to grant more permissive access rights to the registry, it is really not the done thing. Please forget that I even mentioned this possibility!
如果您的应用程序是 .NET,则使用
CommonApplicationData
- 您可以通过调用GetFolderPath
。编辑 - 根据评论:
您需要正确设置 ACL - 有关如何执行此操作的示例源代码,请参阅 http://www.codeproject.com/Tips/61987/Allow-write-modify-access-to-CommonApplicationData
IF your app is .NET then use
CommonApplicationData
- you can get the real location by callingGetFolderPath
.EDIT - as per comments:
You need to setup ACL correctly - for sample source code on how to do this see http://www.codeproject.com/Tips/61987/Allow-write-modify-access-to-CommonApplicationData
公共用户目录怎么样?例如:
C:\Users\Public\Libraries
或C:\Users\Public\Documents
我注意到我的几台 Windows 7 计算机上有这些文件夹。我不确定它是否总是存在,但可能是一个选择。我希望公共用户有类似
%appdata%
的东西,但我发现的最接近的东西是Public\Libraries
。(顺便说一句,
C:\Users\Public\Desktop
确实需要管理员写入。)What about Public User directories? For Example:
C:\Users\Public\Libraries
orC:\Users\Public\Documents
I've noticed these folder on several of my Windows 7 machines. I'm not sure if it is always there, but might be an option. I was hoping for something like an
%appdata%
for the Public User, but the closest thing I found wasPublic\Libraries
.(As a side note, it appears
C:\Users\Public\Desktop
does require admin to write to.)使用 %APPDATA%/Company/Product 作为目录怎么样?
what about using %APPDATA%/Company/Product for the directory?