2010-05-27 118 views
33

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

回答

51

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

你可以找到的SID列表有以各种各样的价值,包括其中包括他们的用户名,他们的“家路”。

我不知道这是多么可靠,我不会推荐搞这个,除非你确定你在做什么。

+0

正是我需要的。谢谢! – modz0r 2010-05-27 08:22:59

+9

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ hivelist似乎只是当前在每个系统上登录的用户(Xp - 7)我已经看过了...而且我不会考虑HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ProfileList \ \ ProfileImagePath确定用户名的可靠方法(请参阅http://support.microsoft.com/kb/2454362)。 – user66001 2012-11-23 21:51:10

20

可以从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

+0

不幸的是,我得到的SID与Windows 7 x64上的HKEY_USERS下的值不匹配。 – 2014-05-24 04:16:33

+0

合法的SID可能看似不存在,因为该特定用户的配置单元当时没有正确加载。'Runas/profile/user:desireduser somearbitrarycommand'会加载它。 – amonroejj 2016-10-13 12:55:03

0

干过,由一点创意的节目,

  1. 枚举在HKEY_USERS钥匙的那些有趣的数字键...

  2. 枚举了在HKEY_LOCAL_MACHINE \ SOFTWARE键\微软\窗户NT \ CURRENTVERSION \ ProfileList文件\

,你会发现同样的数字....现在,在这些键看字符串值: ProfileImageP ATH = “someValue中” 其中的值之一:

的 “%SystemRoot%\ system32 \设置\ systemprofile” ......在这一个...作为它不是一个 目录路径不感兴趣......

的%SystemDrive%\ Documents和Settings \本地服务 - “本地服务” 的%SystemDrive%\ Documents和Settings \网络服务 “网络服务”

的%SystemDrive%\ Documents和Settings \用户名,翻译直接映射到大多数未被篡改的系统中的“USERNAME”值,即。用户在几周后没有更改其用户名或明确更改路径...

+2

“”%systemroot%\ system32 \ config \ systemprofile“...因为它不是目录路径...”不正确。试试c&p到运行对话框中。 – user66001 2012-11-23 21:54:15

+0

(已确认在WinXP + 7上运行) – user66001 2012-11-23 22:00:35

11
  1. 开放注册HKEY_LOCAL_MACHINE \ SOFTWARE \微软\的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网络],则以前登录在机器上。

+4

3包含错误,而不是明智的建议。 [ProfileImagePath]不必以路径c:\ Users开头...查看https://www.google.com/#hl=zh-CN&tbo=d&output=search&sclient=psy-ab&q=move+windows+7+用户+目录;此外,正如其他地方对此线程发表的评论以及@spade所述,如果用户/管理员已更改用户名后帐户创建和登录,则配置文件目录名将不再与用户名(http://support.microsoft.com )/ kb/2454362) – user66001 2012-11-23 21:59:15

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

您可能想使用'code'标记“标记”来设置此代码示例的格式:) – summea 2013-05-21 19:34:53

2

你可以使用来自微软的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 

NB:

  • 当用户是域/ 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

2

通过搜索我的注册表中的用户ID,我发现

HKEY_CURRENT_USER\Volatile Environment\Username