在 C++ 中获取计算机上的用户配置文件列表Win32
枚举计算机上所有用户配置文件的最佳方法是什么?
我知道如何获取当前登录的用户配置文件,并且我知道如何获取“所有用户”配置文件。但我想获得计算机上每个配置文件的列表。
What is the best way to enumerate all of the user profiles on a computer?
I know how to get the currently logged in user profile, and I know how to get the "all user" profile. But I'd like to get a list of each and every profile on the computer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在像 flokra 建议的那样采用无证路线之前,我会尝试 NetUserEnum () 或 NetQueryDisplayInformation()
如果您想进入无证领域,
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
有一个(不完整的)帐户列表(它缺少 ASPNET、HelpAssistant 和 SUPPORT_xxxx 等特殊帐户)它还有配置文件文件夹的路径,这比使用%ALLUSERSPROFILE%\..\
安全得多,但是为什么在存在时使用它GetProfilesDirectory()Before going the undocumented route like flokra suggests, I would try NetUserEnum() or NetQueryDisplayInformation()
If you want to go into undocumented land,
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
has a (incomplete) list of accounts (It's missing special accounts like ASPNET, HelpAssistant and SUPPORT_xxxx) It also has the path to the profile folder, which is a lot safer than using%ALLUSERSPROFILE%\..\
but why use it when there is GetProfilesDirectory()在存在漫游配置文件的情况下,我会非常小心。何时计算计算机上的漫游配置文件?另外,您有足够的权限访问它吗?即使本地管理员也没有网络帐户的权限,只有网络管理员可以执行 IIRC。
I'd be very careful with that, in the presence of roaming profiles. When do you count a roaming profile to be on the computer? Also, do you have sufficient rights to access it? Even Local Admins don't have rights to network accounts, only network admins do IIRC.
您可以读取
%ALLUSERSPROFILE%
上一级目录的内容。然后,您将获得系统上(或曾经,如果没有完全删除)的所有帐户的名称。要验证帐户是否仍然存在,我将使用 LsaLookupNames2< /a>.此函数检索属于帐户名称的 SID(已删除的帐户 == 无 SID)。
You could read in the contents of the directory one level above
%ALLUSERSPROFILE%
.Then you would have the names of all accounts that are (or were, if not deleted completely) on the system. To verify that an account still exists, I would use LsaLookupNames2. This function retrieves the SIDs that belong to account-names (deleted account == no SID).