如何检索存储在计算机上的所有用户配置文件的用户名和域?
这是用户配置文件管理器的屏幕截图,以说明我的意思:
配置文件由 SID 映射。映射存储在此注册表项中:
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList]
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
子键中的值是否指向现有文件夹:
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