特定用户的SHGetFolderPath() [英] SHGetFolderPath() for a specific user

查看:109
本文介绍了特定用户的SHGetFolderPath()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种获取特定用户的本地应用程序数据文件夹的好方法-无需输入该用户的登录详细信息。

I'm looking for a good way to get the local application data folder for a specific user -- without having to enter the login details for that user.

SHGetFolderPath()可以接受我想要为其获取本地appdata文件夹的任何用户的访问令牌,但是要获取访问令牌,您必须提供用户密码。另外,根据 docs ,这是 t在< = Windows 2000上受支持。

SHGetFolderPath() can accept an access token for whatever user I want to get the local appdata folder for, but to get an access token, you have to provide the user's password. Also, according to the docs this isn't supported on <= Windows 2000.

注册表项 HKCU\软件\Microsoft\Windows\CurrentVersion\Explorer\Shell文件夹包含AppData值,该值包含当前用户的本地appdata文件夹的位置...因此,我可以从技术上为特定用户安装HKCU配置单元并访问该值;但是,Microsoft似乎强烈不鼓励使用此密钥,而且我听说它有时也可能不准确。

The registry key HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folder contains the AppData value, which contains the location of the local appdata folder for the current user... so I could technically mount the HKCU hive for the specific user and access this value; however, Microsoft seems to strongly discourage the use of this key, and I've heard that it can occasionally be inaccurate as well.

具有讽刺意味的是,在Windows上,管理员帐户如果他们只是打开资源管理器并浏览到正确的位置,则可以轻松访问和修改任何用户的appdata文件夹中的所有数据...但是似乎没有一种简便的方法可以通过编程方式获取appdata文件夹的位置

Ironically, on Windows, an administrator account can easily access and modify all of the data in any user's appdata folder, if they just open up Explorer and browse to the correct location... but there doesn't seem to be an easy way to programmatically get the location of the appdata folder for a specific user.

那么我还有其他选择吗?目前,访问注册表(gasp)似乎是最好的选择,但是我想使用一些正式的东西,如果可能的话,Microsoft最好不要这样做。

So do I have any other options? Right now, accessing the registry (gasp) seems like the best option, but I'd like to use something official and not discouraged by Microsoft, if possible.

任何建议将不胜感激。

推荐答案

没有文档记录没有令牌AFAIK的方法,但是最好的选择是:

There is no documented way to do this without the token AFAIK, but your best bet is to:


  1. 查找个人资料:HKLM\SOFTWARE\Microsoft\ \Windows NT\CurrentVersion\ProfileList(%windir%\Win9x上的配置文件)

  2. SE_RESTORE_NAME
  3. 的AdjustTokenPrivileges
  4. RegLoadKey NTUSER.DAT(9x上为USER.DAT)

  5. 查询... \CurrentVersion\Explorer\用户Shell文件夹

  1. Find the profile: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList (%windir%\Profiles on Win9x)
  2. AdjustTokenPrivileges for SE_RESTORE_NAME
  3. RegLoadKey NTUSER.DAT (USER.DAT on 9x)
  4. Query ...\CurrentVersion\Explorer\User Shell Folders

请注意,要检查的正确注册表项是用户Shell文件夹而不是Shell文件夹(而且您可能必须扩展路径),请参见 Shell的漫长而可悲的故事文件夹键以获取详细信息

Note that the correct registry key to check is User Shell Folders and not Shell Folders (And you might have to expand the path), see The long and sad story of the Shell Folders key for details

我还想指出,如果可能,应将数据存储在pr中。 ogramfile或常用文件夹,然后在您的程序首次为每个用户运行时复制到配置文件中

I also want to point out that if possible, you should store the data in programfiles or the common folders and then copy into the profile when your program runs for the first time for each user

这篇关于特定用户的SHGetFolderPath()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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