如何使用 powershell 以编程方式查找用户 HKEY_USERS 注册表项? [英] How can I programmatically find a users HKEY_USERS registry key using powershell?

查看:68
本文介绍了如何使用 powershell 以编程方式查找用户 HKEY_USERS 注册表项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您知道该用户在本地计算机上的登录名,我想知道是否有办法在 HKEY_USERS 中找到该用户的注册表项.我想以编程方式将内容添加到特定用户的注册表项(例如 Autorun),但我只知道用户名.如何确定 HKEY_USERS 中的哪些神秘用户实际上属于特定用户名?

I wonder if there is a way to find a local user's registry key in HKEY_USERS if you know the login-name of that user on the local machine. I want to programmatically add stuff to a specific user's registry keys (Autorun for example), but I only know the username. How can I determine which of the cryptic users in HKEY_USERS actually belongs to a specific username?

推荐答案

$User = New-Object System.Security.Principal.NTAccount($env:UserName)
$sid = $User.Translate([System.Security.Principal.SecurityIdentifier]).value

以上代码段为您提供了登录用户的 SID.当附加到 HKEY_USERS 时,它会为您提供该用户名的正确路径.

The above snippet gives you the SID of the logged-in user. This when appended to the HKEY_USERS givs you the right path for that username.

New-PSDrive HKU Registry HKEY_USERS
Get-Item "HKU:\${sid}"

这篇关于如何使用 powershell 以编程方式查找用户 HKEY_USERS 注册表项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆