Category filter
Script to automatically log in to a user account on Windows
You can run PowerShell scripts to carry out a wide range of administrative tasks on your Windows endpoints. For example, executing this PowerShell script can remotely unlock your Windows PC so that the device end-user can automatically sign in to the device without entering any credentials. That’ll be useful for users when in a trusted environment as they won’t be inconvenienced by a lock screen every time they need to log in to the device. You can also use this script when a user’s device needs to be temporarily shared with another user without having to share the device password.
With Hexnode, you can seamlessly push custom scripts remotely on your Windows devices using the Execute Custom Script action.
PowerShell script to automatically log in to a user account on Windows
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$Username = $args[0] $key = $args[1] $RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' If ((Get-Item -Path $RegistryPath).GetValue('ForceAutoLogon') -ne '1') {Set-ItemProperty -Path $RegistryPath -Name 'ForceAutoLogon'-Value 1} If ((Get-Item -Path $RegistryPath).GetValue('AutoAdminLogon') -ne '1') {Set-ItemProperty -Path $RegistryPath -Name 'AutoAdminLogon'-Value 1} If ((Get-Item -Path $RegistryPath).GetValue('DefaultUsername') -ne $Username) {Set-ItemProperty -Path $RegistryPath -Name 'DefaultUsername'-Value $Username } If ((Get-Item -Path $RegistryPath).GetValue('DefaultPassword') -ne $key) {Set-ItemProperty -Path $RegistryPath -Name 'DefaultPassword'-Value $key } Restart-Computer -Force |
This script requires two Arguments:
- Username of the account to be signed in.
- Password associated with the account.
Place the above two arguments in the Arguments box, separated using spaces. The device will automatically be restarted on executing the script successfully to apply the changes. On restarting, the user will get automatically signed in to the user account.
The device will continue signing in to the user account automatically every time you turn on the device or sign out from the account, effectively locking out all the other user accounts present on the device. Therefore, you can also use this script in a kiosk environment to prevent users from signing out of the kiosk user account.
To disable automatic sign-in on the device, you can execute the PowerShell script below:
1 2 3 4 5 6 7 |
$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' If ((Get-Item -Path $RegistryPath).GetValue('ForceAutoLogon') -ne '0') {Set-ItemProperty -Path $RegistryPath -Name 'ForceAutoLogon'-Value 0} If ((Get-Item -Path $RegistryPath).GetValue('AutoAdminLogon') -ne '0') {Set-ItemProperty -Path $RegistryPath -Name 'AutoAdminLogon'-Value 0} Restart-Computer -Force |