Windows 7 Autologon only works after second application

Configuring Autologon on a Windows 7 Device is actually pretty easy. You specify a few Registry Keys and most of the time you are good and your Device is performing an Autologon from this time on.

Generally you have to ask yourself if an Autologon, especially in Company Networks, is a good idea because of potential Security Risks. However, there are always some exceptions like Production Terminals, Kiosk Computers, etc.

For configuring Autologon, I always used the following PowerShell Script, which is setting the required Registry Keys:

# Credentials
$username = 'john.doe'
$password = 'Pa$$w0rd'
$domain = 'CONTOSO'

# Activate Autologon via Registry
New-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'AutoAdminLogon' -PropertyType 'String' -Value '1' -Force
New-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'DefaultUserName' -PropertyType 'String' -Value $username -Force
New-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'DefaultPassword' -PropertyType 'String' -Value $password -Force
New-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'DefaultDomainName' -PropertyType 'String' -Value $domain -Force

Today, I had a pretty weird issue. After running this Script on a Windows 7 Computer and performing a Restart afterwards to test the Configuration, Windows didn’t perform an Autologon and stopped normally on the User Login Screen. Looking again in the Registry, I noticed that the previously set Registry Value AutoAdminLogon was reset to 0 and DefaultPassword was deleted.

Now to make this even more interesting, after running the same script again a second time and perform a Reboot afterwards, Autologon worked without any issues.

After a few hours of troubleshooting and monitoring the Registry on different steps, I figured out that after you apply the Script for the first time and perform a reboot, the existing Registry Value AutoLoginCount was deleted as well with DefaultPassword.

autologin_win7_part1

The Resolution I came up with, was to modify my above script to set the needed Registry Values for Autologon and afterwards delete the AutoLoginCount Value

# Credentials
$username = 'john.doe'
$password = 'Pa$$w0rd'
$domain = 'CONTOSO'

# Activate Autologon via Registry
New-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'AutoAdminLogon' -PropertyType 'String' -Value '1' -Force
New-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'DefaultUserName' -PropertyType 'String' -Value $username -Force
New-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'DefaultPassword' -PropertyType 'String' -Value $password -Force
New-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'DefaultDomainName' -PropertyType 'String' -Value $domain -Force

# Remove AutoLogonCount Value
Remove-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name 'AutoLogonCount' -Force

With this modification, Autologon was working again on the first try. 🙂

I hope the above information will help you if you experience the same Problem.

5/5 - (2 votes)

9 Comments

  1. Cantoris 21. April 2016
  2. Bob 17. October 2016
  3. Bob 17. October 2016
  4. John 1. September 2017
  5. diagg 31. October 2017
  6. Francisco José 15. July 2021
  7. Thomas Scalet-Binder 11. July 2022

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.