我应该在哪里存储配置文件?

编程入门 行业动态 更新时间:2024-10-26 19:34:42
本文介绍了我应该在哪里存储配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要通过Win8读取配置文件并将其写入WinXP中的Windows磁盘.他们在哪里做这件事的最好地方?似乎ProgramData文件夹不允许使用

I need to read and write a configuration file to windows disk in WinXP through Win8. Where is they best place to do this? Doesn't seem like the ProgramData folder is allowing

procedure TfrmMain.FormCreate(Sender: TObject); var path: array[0..MAX_PATH] of char; begin SHGetFolderPath(0, CSIDL_COMMON_APPDATA, 0, SHGFP_TYPE_CURRENT, @path); AppPath:= Path; AppPath:= AppPath + '\Customer\'; if not DirectoryExists(AppPath) then CreateDir(AppPath); if FileExists(AppPath + 'Customers.cst') then LoadFromFile(AppPath + 'Customers.cst'); end; procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if ListModified then begin if MessageDlg('Save Changes?', mtWarning, [mbYes, mbNo], 0) = mrYes then SaveToFile(AppPath + 'Customers.cst'); canClose:= True; end else canClose:= False; end;

推荐答案

CSIDL_COMMON_APPDATA 是描述为:

包含所有用户的应用程序数据的文件系统目录.

The file system directory that contains application data for all users.

由于它是计算机上所有用户之间共享的,因此您需要具有管理员权限才能写入该位置.如果您希望所有用户共享您的配置,那么 CSIDL_COMMON_APPDATA 是正确的选择.但是,当您在此处写东西时,需要确保您具有足够的权限.

Because it is shared between all users on the computer, you need to have admin rights to write to that location. If you want your configuration to be shared by all users then CSIDL_COMMON_APPDATA is the right place for it. However, you'll need to make sure that you have sufficient rights when you come to write there.

如果确实需要您的应用程序写入 CSIDL_COMMON_APPDATA ,那么通常的方法是在安装过程中为您的应用程序创建目录.因为您的安装程序将提升运行,所以可以这样做.它还必须在新目录中添加允许的ACL,以便您的应用程序以后可以在以标准用户身份运行时写入该文件夹.

If you do need your application to write to CSIDL_COMMON_APPDATA then the normal approach is to create a directory for your application during installation. Because your installer will run elevated it can do this. It must also add a permissive ACL to the new directory so that your application can later, when running as standard user, write to that folder.

如果要在用户配置文件中存储配置,则应在 CSIDL_APPDATA 下选择一个位置,描述为:

If you want a configuration that is stored in the user profile then you should choose a location under CSIDL_APPDATA, described as:

文件系统目录,用作特定于应用程序的数据的公共存储库.

The file system directory that serves as a common repository for application-specific data.

由于这是在用户配置文件中,因此计算机上的每个用户都将拥有单独的配置文件副本.

Because this is in the user profile, each user on the machine will have a separate copy of the configuration file.

更多推荐

我应该在哪里存储配置文件?

本文发布于:2023-10-15 11:56:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1494271.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:配置文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!