How can I programmatically find a users HKEY_USERS registry key using powershell?

后端 未结 3 656
-上瘾入骨i
-上瘾入骨i 2021-02-04 05:58

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

3条回答
  •  不要未来只要你来
    2021-02-04 06:09

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

    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}"
    

提交回复
热议问题