Get CSIDL_LOCAL_APPDATA path for any user on Windows(获取 Windows 上任何用户的 CSIDL_LOCAL_APPDATA 路径)
问题描述
是否有任何 Win32/MFC API 可以为我想要的 any 用户(不仅是当前登录的用户)获取 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 "domainuser" and I want to get a list of their paths - is that possible?
推荐答案
您可以获取用户的SID,然后在HKLMSOFTWAREMicrosoftWindows NTCurrentVersionProfileList 下查找并获取ProfileImagePath 值.
You can get the SID for the user and then look it up under HKLMSOFTWAREMicrosoftWindows NTCurrentVersionProfileList and get the ProfileImagePath value.
获得此路径后,您可以为您的用户获取 CLSID_LOCAL_APPDATA,将绝对路径转换为您的配置文件的相对路径,然后将该相对路径附加到其他用户配置文件路径.
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.
但是,请记住,这依赖于未记录的注册表项,并且可能会在未来版本的操作系统中中断.(或者,正如 Raymond Chan 所说:既然你知道该怎么做,让我告诉你为什么不应该这样做……":-))
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..." :-))
如果您有代表用户的令牌,您可以使用 SHGetFolderPath 或 SHGetKnownFolderPath(在 Vista 及更高版本上).但是,存在一定的安全限制,您应该在 MSDN 上阅读以了解详细信息.
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).aspxSHGetKnownFolderPath - http://msdn.microsoft.com/en-us/library/bb762188(VS.85).aspx
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 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取 Windows 上任何用户的 CSIDL_LOCAL_APPDATA 路径
基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
