如何获取所有本地存储的用户配置文件的用户名和域? [英] How to get the user names and domains of all locally stored user profiles?
本文介绍了如何获取所有本地存储的用户配置文件的用户名和域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检索存储在计算机上的所有用户配置文件的用户名和域?
How do I retrieve the user names and domains of all user profiles stored on a computer?
这是用户配置文件管理器的屏幕截图,以说明我的意思:
Here's a screenshot of the User Profiles manager to illustrate what I mean:
推荐答案
配置文件由 SID 映射.映射存储在此注册表项中:
The profiles are mapped by SID. The mapping is stored in this registry key:
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList]
您可以使用 WMI 来枚举 SID 和 解析到用户名和域名:
You can use WMI to enumerate the SIDs and resolve them to user and domain name:
Const HKLM = &h80000002
Const profiles = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
Set wmi = GetObject("winmgmts://./root/cimv2")
Set reg = GetObject("winmgmts://./root/default:StdRegProv")
reg.EnumKey HKLM, profiles, subkeys
For Each sid In subkeys
Set acct = wmi.Get("Win32_SID.SID='" & sid & "'")
WScript.Echo acct.ReferencedDomainName & "\" & acct.AccountName
Next
如果您只查找现有配置文件夹的用户/域,请检查子项中的 ProfileImagePath
值是否指向现有文件夹:
If you're looking for the user/domain of existing profile folders only, check if the ProfileImagePath
value inside the subkeys points to an existing folder:
Const HKLM = &h80000002
Const profiles = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set wmi = GetObject("winmgmts://./root/cimv2")
Set reg = GetObject("winmgmts://./root/default:StdRegProv")
reg.EnumKey HKLM, profiles, subkeys
For Each sid In subkeys
reg.GetStringValue HKLM, profiles & "\" & sid, "ProfileImagePath", path
path = sh.ExpandEnvironmentStrings(path)
If fso.FolderExists(path) Then
Set acct = wmi.Get("Win32_SID.SID='" & sid & "'")
WScript.Echo acct.ReferencedDomainName & "\" & acct.AccountName
End If
Next
这篇关于如何获取所有本地存储的用户配置文件的用户名和域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文