获取 Windows 上任何用户的 CSIDL_LOCAL_APPDATA 路径

2022-01-12 00:00:00 winapi visual-c++ mfc shell32

是否有任何 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

相关文章