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 路径
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
