从HKEY_USERS值中获取用户名

时间:2010-05-27 07:40:52

标签: windows vbscript registry wmi

有没有办法将HKEY_USERS下的值连接到实际用户名?
我看到了一些类似的问题,但大多数(如果不是全部)都讨论了C#代码,我需要的是VBScript。

9 个答案:

答案 0 :(得分:61)

如果您查看以下任一键:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist

您可以在其中找到具有各种值的SID列表,包括其“主路径”包含其用户名的位置。

我不确定这是多么可靠,除非你真的确定你在做什么,否则我不建议搞乱这个。

答案 1 :(得分:24)

可以从WMI查询此信息。以下命令将输出一个表,其中包含每个用户的行以及每个用户的SID。

wmic useraccount get name,sid

您也可以将此信息导出为CSV:

wmic useraccount get name,sid /format:csv > output.csv

我在Vista和7上使用过此功能。有关详细信息,请参阅WMIC - Take Command-line Control over WMI

答案 2 :(得分:12)

  1. 打开Reg HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ProfileList \

  2. 制作循环以获取所有子键

  3. 您感兴趣的子键是以[S-1-5-21-]开头的子键,表示用户(请参阅键名[ProfileImagePath],它们始终以路径c:\ Users开头)

  4. 以[S-1-5-21-12]开头的人都是本地用户

  5. 以[S-1-5-21-13]开头的人都是网络用户[如果加入Domained网络],这些用户以前是在机器上登录的。

答案 3 :(得分:4)

通过在注册表中搜索我的用户ID,我找到了

HKEY_CURRENT_USER\Volatile Environment\Username

答案 4 :(得分:3)

您可以使用Microsoft的SysInternals团队中的命令PSGetSid。

下载网址:http://technet.microsoft.com/en-gb/sysinternals/bb897417.aspx

用法:

psgetsid [\\computer[,computer[,...] | @file] [-u username [-p password]]] [account|SID]
-u  Specifies optional user name for login to remote computer.
-p  Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.
Account PsGetSid will report the SID for the specified user account rather than the computer.
SID PsGetSid will report the account for the specified SID.
Computer    Direct PsGetSid to perform the command on the remote computer or computers specified. If you omit the computer name PsGetSid runs the command on the local system, and if you specify a wildcard (\\*), PsGetSid runs the command on all computers in the current domain.
@file   PsGetSid will execute the command on each of the computers listed in the file.

示例:

psgetsid S-1-5-21-583907252-682003330-839522115-63941

注意:

  • 如果用户是域/ AD(LDAP)用户,则在域上的任何计算机上运行此用户应该会得到相同的结果。
  • 如果用户是本机的本地用户,则该命令应该在该计算机上运行,​​或者您应该通过可选参数指定计算机。

<强>更新

如果您使用PowerShell,以下内容可能对解析列出的任何AD用户非常有用:

#create a drive for HKEY USERS:
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS -ErrorAction SilentlyContinue

#List all immediate subfolders
#where they're a folder (not a key)
#and they's an SID (i.e. exclude .DEFAULT and SID_Classes entries)
#return the SID
#and return the related AD entry (should one exist).
Get-ChildItem -Path 'HKU:\' `
| ?{($_.PSIsContainer -eq $true) `
-and ($_.PSChildName -match '^S-[\d-]+$')} `
| select @{N='SID';E={$_.PSChildName}} `
, @{N='Name';E={Get-ADUser $_.PSChildName | select -expand Name}}

您还可以进一步优化SID过滤器,以便只撤回那些将解析为AD帐户的SID(如果您愿意);更多关于SID结构的信息:https://technet.microsoft.com/en-us/library/cc962011.aspx

答案 5 :(得分:1)

for /f "tokens=8 delims=\" %a in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist" ^| find "UsrClass.dat"') do echo %a

答案 6 :(得分:0)

通过一些创意编程完成它,

  1. 在HKEY_USERS中为这些有趣的数字键添加密钥......

  2. 在HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ProfileList \

  3. 中枚举键

    你会发现相同的数字....现在在这些键中查看String值: ProfileImagePath =“SomeValue”,其值为:

    “%systemroot%\ system32 \ config \ systemprofile”...对此不感兴趣...因为它不是 目录路径......

    %SystemDrive%\ Documents and Settings \ LocalService - “本地服务” %SystemDrive%\ Documents and Settings \ NetworkService“NETWORK SERVICE”

    %SystemDrive%\ Documents and Settings \ USER_NAME,它直接转换为大多数未被篡改的系统中的“USERNAME”值,即。用户几周后没有更改用户名或明确更改路径...

答案 7 :(得分:0)

HKEY_USERS\oneyouwanttoknow\中,您可以查看\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders,它将显示其配置文件路径。 c:\users\whothisis\Desktop

答案 8 :(得分:0)

执行此操作的正确方法需要利用SAM注册表配置单元(在Windows 10上,这需要NT AUTHORITY\SYSTEM特权)。您所需的信息在密钥HKEY_LOCAL_MACHINE\SAM\SAM\Domains\Account\Users\Names中。

每个子项是用户名,每个子项中的默认值是一个二进制整数。该值(转换为十进制)实际上对应于SID的最后一块。

例如,以“管理员”为例,默认情况下它与整数0x1f4(或500)相关联。

因此,从理论上讲,您可以根据HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList键和/或HKEY_USERS键的子键名称构建一个SIDS列表,解析出最后一个连字符(- ),并将其与SAM配置单元中的信息进行比较。

如果您没有NT AUTHORITY\SYSTEM特权,那么解决此问题的下一个最佳方法可能是遵循此处答案中所述的另一种方法。

参考:https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/81d92bba-d22b-4a8c-908a-554ab29148ab