gpt4 book ai didi

windows - 在 Windows 上,在哪里保存依赖于机器(而不是用户)的 ini 文件

转载 作者:可可西里 更新时间:2023-11-01 13:27:52 24 4
gpt4 key购买 nike

我的应用程序当前将设置存储在当前用户配置文件下的 INI 文件中(在 WinXP 下为 C:\Documents and Settings\<CurrentUser>\Application Data\MyApplication\MySettings.ini)。但我意识到其中一些设置是机器独有的,而不是用户独有的,因此希望(实际上需要)将它们保存在一个位置供所有用户使用。

在 Windows XP(及更高版本)上是否有文件夹位置可以存储用户独立设置?

注意:我不想将它们存储在与我的应用程序相同的文件夹中,也不想将它们存储在注册表中。

我注意到“C:\Documents and Settings\”下有一个“All Users”文件夹?我应该存放在下面吗?

奖励积分:我更有可能将答案奖励给任何能告诉我如何在 Delphi 7 中从 Windows 返回此路径的人。

最佳答案

对于 XP,Windows 提供了 SHGetFolderPath()得到一个已知的位置。您要查找的 CSIDL 是 CSIDL_COMMON_APPDATA ,描述为:

The file system directory that contains application data for all users. A typical path is "C:\Documents and Settings\All Users\Application Data". This folder is used for application data that is not user specific. For example, an application can store a spell-check dictionary, a database of clip art, or a log file in the CSIDL_COMMON_APPDATA folder. This information will not roam and is available to anyone using the computer.

对于 Vista 及更高版本,这已替换为 SHGetKnownFolderPath()尽管 SHGetFolderPath() 仍然可以用作它的包装函数。如果你使用真正的 Vista 调用,你应该使用 FOLDERID_ProgramData而不是 CSIDL_COMMON_APPDATA .

此链接here似乎展示了一种方法。

似乎归结为这个(慎重对待,我不太了解Delphi):

function ShGetKnownFolderPath (
const rfid: TGUID;
dwFlags: DWord;
hToken: THandle;
out ppszPath: PWideChar): HResult;
var
Shell: HModule;
Fn: TShGetKnownFolderPath;
begin
Shell := LoadLibrary ('shell32.dll');
Win32Check(Shell <> 0);
try
@Fn := GetProcAddress (Shell, 'SHGetKnownFolderPath');
Win32Check (Assigned (Fn));
Result := Fn (rfid, dwFlags, hToken, ppszPath);
finally
FreeLibrary (Shell);
end;
end;

function GetKnownFolderPath (
const rfid: TGUID;
dwFlags: DWord;
hToken: THandle): WideString;
var
buffer: PWideChar;
ret: HResult;
begin
ret :=ShGetKnownFolderPath (rfid, dwFlags, hToken, buffer);
OleCheck (ret);
try
Result := buffer;
finally
CoTaskMemFree (buffer);
end;
end;

This page提供所有 CSIDL_* 的列表和 FOLDERID_*值。请记住,您也应该将这些函数用于您的用户特定数据,而不是像 "C:\Documents and Settings\<CurrentUser>\Application Data\" 这样的硬编码值。 .可能是不同语言版本的 Windows 使用不同的目录名称,也可能是用户可以随意移动他们的数据区域。

关于windows - 在 Windows 上,在哪里保存依赖于机器(而不是用户)的 ini 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1258146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com