我应该在哪里存储配置文件? [英] Where should I store a configuration file?

查看:74
本文介绍了我应该在哪里存储配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过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.

这篇关于我应该在哪里存储配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆