llarava
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\SOFTWAR E\Microsof t\Windows NT\CurrentVersion\Winlogon \DefaultUs erName
Can you guys help?
Thank you!
Via script vbs/powershell I am trying to get the logged on username value and then write this value (username) into HKEY_LOCAL_MACHINE\SOFTWAR
Can you guys help?
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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_MACH INE\SOFTWA RE\Microso ft\Windows NT\CurrentVersion\Winlogon ' -Name DefaultUserName -Value $env:UserName
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACH
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.
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.
ASKER
For example
Read the value from CLIENTNAME
HKEY_LOCAL_MACHINE\SOFTWAR
Write the vale to the Winlogon key
HKEY_LOCAL_MACHINE\SOFTWAR