使用SHGetSpecialFolderPath检索可以访问非管理员用户的哪个CSIDL可以访问的应用程序文件夹? [英] Usage of SHGetSpecialFolderPath to retrieve an application folder that can be accessed also to non admin users, which CSIDL to choose?

查看:167
本文介绍了使用SHGetSpecialFolderPath检索可以访问非管理员用户的哪个CSIDL可以访问的应用程序文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的应用程序中,我在每个机器上存储一个应用程序文件夹中的一些文件。 b

  .. \Project1\LoginHistory(登录历史记录文件 - 所有用户通用)
..\Project1\Translations(本地化文件 - 所有用户通用)
..\Project1\FormSettings\User1\(这包含一个用于User1的窗体的一个ini文件)
..\Project1\FormSettings\UserN\\ \\(这包含每个窗体的UserN的一个ini文件)

所以你可以看到为什么我使用这个:保存特定于机器的一些数据(记住从本机产生的最新登录,一种MRU),以存储翻译字符串或第三方组件(这些是从exe资源中提取的运行时间),并保存一些用户特定的数据(如形式大小)。真实的情况比较复杂,但至少你可以得到一些通用文件夹和一些用户文件夹。



现在我想保留这个结构,所以我的所有文件在一个.. .. \Project1文件夹(+子文件夹)。即使是因为用户不是Windows用户,而是SQL Server用户。



我的问题是为 .. \选择哪个文件夹



目前,我(成功)使用此代码检索 .. \

 使用ShlObj; 

函数GetSpecialFolder(const CSIDL:integer):string;
var
RecPath:PWideChar;
begin
RecPath:= StrAlloc(MAX_PATH);
try
FillChar(RecPath ^,MAX_PATH,0);
如果SHGetSpecialFolderPath(0,RecPath,CSIDL,false)
then result:= RecPath
else result:='';
finally
StrDispose(RecPath);
结束
结束

我用

  GetSpecialFolder(CSIDL_APPDATA)

定义CDISL的列表 here



GetSpecialFolder(CSIDL_APPDATA)返回 C:\Users\username\AppData\Roaming 在Windows 7中。



所以这样以前工作,但最近我收到一些客户似乎直接与这些文件夹中的读/写问题有关的投诉。 (例如 C:\Users\username\AppData\Roaming\Project1\LoginHistory - 使用上面列出的文件夹)。



所以我的问题是:使用 CSIDL_APPDATA 是否正确?你有另一个建议吗?有没有机会在某些操作系统或某些用户真正减少权限的情况下,该文件夹可能会有读/写问题?



请记住,我不想对我的文件有多个根文件夹。

解决方案

我最后使用的方法是正确的。因为我真的不需要我的应用程序的通用文件(所有临时文件都是用户特定的 - 因为几个常见的东西存储在数据库中) CSIDL_APPDATA 是一个很好的地方。



我面临的问题还不清楚,但我怀疑是因为login.ini是一个保留字(只有最近才有)在最近的Windows更新后可能)。



我已经问过这个问题


In my application I store on every machine some files in an application folder.

A simplified version of the real case is this:

..\Project1\LoginHistory (login history file - common for all users)
..\Project1\Translations (localization files - common for all users)
..\Project1\FormSettings\User1\ (this contains an ini file per form for User1)
..\Project1\FormSettings\UserN\ (this contains an ini file per form for UserN)

So you can see why I use this: to save some data that is specific to the machine (remember the latest logins made from this machine, a kind of MRU), to store Translation strings or 3rd party components (these are extracted runtime from exe resources) and for saving some user specific data (like form size). The real case is more complex, but at least you can get that there are some "common folder" and some "user folders".

Now I would like to keep this structure, so all my files in a single ..\Project1 folder (+ subfolders). Even because the users are not the windows users, but they are SQL Server users.

My question is which folder to choose for ..\.

Currently I am (succesfully) using this code for retrieveing ..\

uses ShlObj;

function GetSpecialFolder(const CSIDL: integer) : string;
var
  RecPath : PWideChar;
begin
  RecPath := StrAlloc(MAX_PATH);
    try
    FillChar(RecPath^, MAX_PATH, 0);
    if SHGetSpecialFolderPath(0, RecPath, CSIDL, false) 
      then result := RecPath
      else result := '';
    finally
      StrDispose(RecPath);
    end;
end;

And I call it with

GetSpecialFolder(CSIDL_APPDATA)

Where the list of CDISL is defined here.

GetSpecialFolder(CSIDL_APPDATA) returns C:\Users\username\AppData\Roaming in Windows 7.

So this used to work, but recently I recieved some complaint from some customer that seems directly related to read/write problems in these folders. (for example C:\Users\username\AppData\Roaming\Project1\LoginHistory - using folders listed above).

So my question is: is it correct to use CSIDL_APPDATA? Do you have another suggestion? Is there a chance that on some OS or with some users with really reduced privileges there can be read/write problems on that folder?

Please remember that I would not like to have more than one root folder for my files.

解决方案

The approach I use finally is correct. Since I do not really need common files for my application (it makes sense that all the temp files are user specific - because the few common things are stored in the DB) CSIDL_APPDATA is a good place.

The problem I was facing it is still not clear but I suspect it is due to the fact that login.ini is a reserved word (only recently, after some recent windows update maybe).

I already asked this question.

这篇关于使用SHGetSpecialFolderPath检索可以访问非管理员用户的哪个CSIDL可以访问的应用程序文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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