正确使用Windows用户配置文件目录

发布于 2024-09-15 11:52:15 字数 350 浏览 0 评论 0原文

我需要在 Windows 用户“主”目录中创建一个目录(c:\Documents and Settings\someusername\c:\users\someusername\)。该目录将永久存在,但仅包含临时文件。

如果我想成为一个好公民,该目录在用户个人资料中的最佳位置是什么?我应该注意,我的程序将由(可能)非管理员用户运行,并且只需要访问他们自己的配置文件,但他们必须有权创建该文件夹。

我猜使用 My Documents\NameOfMyApp\ 是可能的,但这似乎是侵入性的。

对于此类数据是否有更好的位置,以及访问它的特定 MFC 调用?

I need to create a directory inside a windows users 'home' directory (c:\Documents and Settings\someusername\ or c:\users\someusername\). This directory will exist permanently but will only contain temporary files.

What is is the best location for this directory within the users profile if I want to be a good citizen? I should note that my program will be run by (possibly) non-admin users and will only need access to their own profile, but they must have permission to create the folder.

Using My Documents\NameOfMyApp\ is possible I guess, but that seems intrusive.

Is there a better location for this type of data, and a specific MFC call to access it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云之铃。 2024-09-22 11:52:15

我会考虑使用 AppData 目录。您可以使用 SHGetSpecialFolderLocation 传递CSIDL_APPDATA; (或许多替代方案 - 几乎每个版本的 Windows 都添加了 SHGetSpecialFolderLocationSHGetSpecialFolderPath,或(通常)两者)。

I'd consider using the AppData directory. You can get its location with SHGetSpecialFolderLocation passing it CSIDL_APPDATA; (or a number of alternatives -- nearly every version of Windows adds a new replacement for SHGetSpecialFolderLocation, SHGetSpecialFolderPath, or (often) both).

从此见与不见 2024-09-22 11:52:15

看一下以下 win32 调用:

您可能想要使用 GetUserProfileDirectory 并将数据放入子目录中与您的应用程序名称。

你一定会想使用这个功能,因为在 vista 及以上版本上没有“\documents and settings”文件夹,他们改为“\user”。

Take a look at the following win32 calls:

You probably want to use GetUserProfileDirectory and put your data in a sub-directory with your appname.

You will definitely want to use the function because there is no "\documents and settings" folder on vista and up, they changed to it "\user".

秋叶绚丽 2024-09-22 11:52:15

作为一个优秀的应用程序公民,您应该使用:
[驱动器]:\Documents and Settings[用户名]\Application Data[应用程序名称] 或
[驱动器]:\Documents and Settings[用户名]\Local Settings\Application Data[应用程序名称]
(在 Vista 和 Win7 上,“文档和设置”被替换,最明智的是用“用户”替换)

环境变量 USERPROFILE 将提供您猜对了的用户配置文件路径。
TEMP 路径提供用户个人临时目录的路径

如果临时文件不是特定于用户的,您可以使用 C:\temp

编辑:如果您要使用特定于用户的位置,我强烈建议您使用环境变量(XP 和 2000 上的 USERPATH)而不是硬编码路径。

-沃尔多

P.S.谢谢你问这个问题。我看到太多应用程序的不良行为。 C: 驱动器的根目录不是您应该倾倒东西的地方!至少,(测试是否存在,必要时创建,并且)使用 C:\Temp。

Being a good application citizen, you should use:
[drive]:\Documents and Settings[username]\Application Data[AppName] or
[drive]:\Documents and Settings[username]\Local Settings\Application Data[AppName]
(On Vista and Win7, "Documents and Settings" is replaced, most sensibly with "Users")

The environment variable USERPROFILE will provide the, you guessed it, User Profile Path.
The TEMP path provides the path to the user's individual temp directory

If the temp files aren't user-specific, you could use C:\temp

EDIT: If you are to use a user-specific location, I highly recommend that you use the environment variables (USERPATH on XP and 2000) rather than hard-coding the paths.

-Waldo

P.S. Thank you for asking this. I see bad behaviour from Waaaay too many applications. The root of the C: drive is not where you should be dumping things! At the very least, (test for the presence of, creating if necessary, and) use C:\Temp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文