Write logged on userID value in current user registry

Hi Team,

I want to set below registry for logged on user but unable to do so.

“userId”=“divyam” (divyam means logged on user)

I’m using below powershell for the same but no luck,

Action Script:

//Set userId Browser Policy for Userlane Extension
$RegistryPath =
$Name = ‘userId’
$Value = $env:UserName

//Create the key if it does not exist
If (-NOT (Test-Path $RegistryPath)) {
New-Item -Path $RegistryPath -Force | Out-Null
New-ItemProperty -Path $RegistryPath -Name $Name -Value $Value -PropertyType String -Force

Have you looked at the regset and regset64 Action Script commands?

1 Like

HKEY_CURRENT_USER doesn’t make sense in the context of an action running as the LocalSystem account.

You either need to use ‘override’ commands to run the action in the context of the user, or change to path with a relevance expression like {user key of current user}\Software\...



You could probably manage this with 1 line of actionscript, using the info provided by @cmcannady and @JasonWalker

regset64 "[{user key of logged on user as string & "\SOFTWARE\Policies\Microsoft\Edge\3rdparty\extensions\abc\policy"}]" "userId"="{name of logged on user}"

You may want to do extra checks in case of systems that do not have a user logged in, or maybe have more than 1 logged in user as those would encounter relevance substitution errors. I used logged on user as this handles remote desktop connection sessions.