3

如何检索存储在计算机上的所有用户配置文件的用户名和域?

这是用户配置文件管理器的屏幕截图,以说明我的意思:

用户资料

4

1 回答 1

3

配置文件由 SID 映射。映射存储在此注册表项中:

[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList]

您可以使用 WMI枚举SID 并将它们解析为用户和域名:

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
于 2013-03-09T12:21:45.673 回答