获取 Windows 上任何用户的 CSIDL_LOCAL_APPDATA 路径
是否有任何 Win32/MFC API 可以为我想要的任何用户(不仅仅是当前登录的用户)获取CSIDL_LOCAL_APPDATA
? 假设我有一个“域\用户”形式的用户列表,我想获取他们的路径列表 - 这可能吗?
Is there any Win32/MFC API to get the CSIDL_LOCAL_APPDATA
for any user that I want (not only the currently logged on one)? Let's say I have a list of users in the form "domain\user" and I want to get a list of their paths - is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以获取用户的 SID,然后在 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList 下查找并获取 ProfileImagePath 值。
获得此路径后,您可以获取用户的 CLSID_LOCAL_APPDATA,将绝对路径转换为您的配置文件的相对路径,然后将该相对路径附加到其他用户配置文件路径。
但是,请记住,这依赖于未记录的注册表项,并且可能会在操作系统的未来版本中出现故障。 (或者,正如 Raymond Chan 所说:“现在您知道如何做到这一点,让我告诉您为什么不应该这样做......”:-))
如果您有代表用户的令牌,那么您可以使用 SHGetFolderPath 或 SHGetKnownFolderPath(在 Vista 及更高版本上)。 但是,存在某些安全限制,您应该阅读 MSDN 以了解详细信息。
SHGetFolderPath - http://msdn.microsoft.com/en-我们/library/bb762181(VS.85).aspx
SHGetKnownFolderPath - http://msdn.microsoft.com/en-我们/library/bb762188(VS.85).aspx
You can get the SID for the user and then look it up under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList and get the ProfileImagePath value.
Once you have this path, you can get CLSID_LOCAL_APPDATA for your user, convert the absolute path to a relative path to your profile and then append that relative path to the other user profile path.
However, keep in mind that this is relying on an undocumented registry key and can break in future versions of the OS. (Or, as Raymond Chan would say: "Now that you know how to do it, let me tell you why you shouldn't do it this way..." :-))
If you have a token representing the user, you can use the SHGetFolderPath or SHGetKnownFolderPath (on Vista and up). However, there are certain security restrictions and you should read up on MSDN for details.
SHGetFolderPath - http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx
SHGetKnownFolderPath - http://msdn.microsoft.com/en-us/library/bb762188(VS.85).aspx