如何获取给定 SID 的用户配置文件?
我需要根据用户名或 SID 获取用户默认配置文件目录。
我该怎么做呢?
GetUserProfileDirectory() 似乎仅适用于当前帐户。
I need to fetch the user default profile directory, given its username or SID.
How can I do it?
GetUserProfileDirectory() seems to work only for the current account.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GetUserProfileDirectory 和 SHGetFolderPath 都能够获取不同帐户的配置文件目录,唯一的问题是它们需要令牌句柄而不是 SID。要获取令牌句柄,您需要知道用户密码并调用 LogonUser,或者如果用户已经登录并且您正在作为服务运行,您可以获取他们的令牌。
我猜这些解决方案都不是您想要的,所以您必须进入未记录的领域:
读取“HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%SID%”下的 ProfileImagePath 值
Both GetUserProfileDirectory and SHGetFolderPath are able to get the profile directory of a different account, the only problem is that they want a token handle and not a SID. To get the token handle you either need to know the users password and call LogonUser, or if the user is already logged on and you are running as a service you can get their token.
I'm guessing neither of those solutions are what you want so then you have to go into undocumented land:
Read the ProfileImagePath value under "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%SID%"