从另一个用户读取本地“HKEY_CURRENT_USER”,Windows 批处理/PowerShell

从另一个用户读取本地“HKEY_CURRENT_USER”,Windows 批处理/PowerShell

好吧,我知道这是一个棘手的问题。我有一个软件可以在网络中的所有计算机中运行验证脚本。我也可以创建自己的脚本。但我发现一个问题,即脚本以具有管理员权限的特定用户身份运行。因此,当我的脚本检查注册表路径时:Computer\HKEY_CURRENT_USER 实际上不是已登录用户的注册表,而是用于运行脚本的用户。

有没有办法在其他登录用户内部运行命令 reg.exe(无需密码)?

到目前为止正在尝试:

:: Get the current console logged user 
for /F "tokens=1" %%f in ('query user ^| find "Active"') do set "ConsoleUser=%%f" 
:: clear the ">" character that sometimes is on the left of the user 
set ConsoleFinal=%ConsoleUser:*>=% 
:: enter the user folder (* at the end, if the user is part of a domain)  
cd c:\users\%ConsoleUser%*  
:: Import the other user registry reg load HKU\test ntuser.dat

但后来我收到错误,提示 ntuser.dat 正在使用中(这是因为其他用户已登录)

简历中:我需要检查当前用户的注册表项,但是是从在不同用户上运行的脚本中检查的。

答案1

如果用户已经登录,他们的注册表将被挂载到HKEY_USERS/%SID%

在 powershell 中,您可以设置到 HKEY_USERS 的映射,然后在那里访问注册表。如果我想获取“系统”帐户的 Conhost 设置,我可以这样做。

PS > New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS
PS > Get-ItemProperty HKU:\S-1-5-18\Console\

相关内容