Link to home
Start Free TrialLog in
Avatar of llarava
llaravaFlag for Afghanistan

asked on

Need script to get logged on user then write value to DefaultUserName registry key

Can you guys please assist with the following:

Via script vbs/powershell I am trying to get the logged on username value and then write this value (username) into HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName

Can you guys help?

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of llarava

ASKER

A different system will read that registry key value. That being said, is there a way to read the value from a registry key and write that value into a different one?

For example

Read the value from CLIENTNAME

HKEY_LOCAL_MACHINE\SOFTWARE\ CITRIX\ICA\SESSION\CLIENTNAME

Write the vale to the Winlogon key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

If Set-ItemProperty writes to the registry, I would look at Get-ItemProperty to read from it.

I find the docs are a great place to look for these things:
https://docs.microsoft.com/en-us/powershell/scripting/getting-started/cookbooks/working-with-registry-entries?view=powershell-6
Can you execute that PowerShell script as the logon script for the user without local admin rights?

Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value $env:UserName
I don't know.  Try it and see.

Some registry values can be user updated and some need elevated permissions.  I don't have a list of what is what.

You should be able to set up some login event at a system level that could probably run it when a user logs in.  I'm not a Windows Admin so I can't tell you what your options are.