获取Windows上任何用户的CSIDL_LOCAL_APPDATA路径 [英] Get CSIDL_LOCAL_APPDATA path for any user on Windows

查看:770
本文介绍了获取Windows上任何用户的CSIDL_LOCAL_APPDATA路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何Win32/MFC API可以为我想要的任何用户(不仅是当前登录的用户)获得CSIDL_LOCAL_APPDATA?假设我有一个域\用户"形式的用户列表,并且我想获取其路径列表-可以吗?

解决方案

您可以获取用户的SID,然后在HKLM \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ProfileList下进行查找,并获取ProfileImagePath值. /p>

一旦有了该路径,就可以为用户获取CLSID_LOCAL_APPDATA,将绝对路径转换为配置文件的相对路径,然后将该相对路径附加到其他用户配置文件路径.

但是,请记住,这依赖于一个未公开的注册表项,并且可能会破坏该操作系统的未来版本. (或者,正如雷蒙德·陈(Raymond Chan)所说:现在,您知道该怎么做了,让我告诉您为什么不应该这样做……":-))

如果您有代表用户的令牌,则可以使用SHGetFolderPath或SHGetKnownFolderPath(在Vista及更高版本上).但是,存在一定的安全限制,您应该在MSDN上阅读有关详细信息.

SHGetFolderPath- http://msdn.microsoft.com /en-us/library/bb762181(VS.85).aspx SHGetKnownFolderPath- http://msdn.microsoft.com/zh- us/library/bb762188(VS.85).aspx

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?

解决方案

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

这篇关于获取Windows上任何用户的CSIDL_LOCAL_APPDATA路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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