Background: As part an automated testing suite I am building, I need to set up Autologon on my virtual machines 'on demand'. By on demand, I mean that I don't want to necessarily pre-configure my VM or any snapshot to have Autologon set up already, for security reasons and also a huge business case.

My solution so far: I'm copying a script to the guest machine and then using Sysinternals PsExec to execute it. The script is:

reg add "hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v DefaultUserName /t REG_SZ /d myusername
reg add "hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v DefaultPassword /t REG_SZ /d myfakepassword
reg add "hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v DefaultDomainName /t REG_SZ /d mydomain
reg add "hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v ForceAutoLogon /t REG_SZ /d 1
reg add "hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /f /v AutoAdminLogon /t REG_SZ /d 1
reg add "hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoLogonChecked" /f /ve /d 1

Note: I don't believe AutoLogonChecked is required for machines post Windows 2000 but I'm doing it just in case for now. Maybe ForceAutoLogon isn't either, not sure yet.

The Problem: I see PsExec executes this properly and all the values are in the registry, however when I restart the machine, the user isn't automatically logged on...When I run this a second time then restart the machine, the user is finally logged on.

A diff between the registry states shows that the first time I run this, it is missing both the "1" for AutoAdminLogon, and also the DefaultPassword key. The second time I execute it, these values are correctly intact as I intended.

So, what is going on here? Is this expected? This post claims in the end that it really all just works (the problem was that a logoff script was setting off the values). Doesn't seem to work for me however.

Note this seems unique to Windows 7, does not occur in Windows XP

Also note that you don't need PsExec to recreate the issue - just modify the registry yourself


  • Login interactively and run script (so, not executing it remotely), logging off automatically logs me back in (so, it works)
  • remotely execute the script in guest when I'm interactively logged in, logging off automatically logs me back in (so, it works)
  • remotely execute the script in guest when with non-interactive session if I log in afterwards (so, interactive now) then back off, it logs me back in (so, it then works)

EDIT/update 2: This only occurs for Win7x86, Win7x64, Win8x64. This does not occur for Windows XP

EDIT 3: I get same behavior using Sysinsternal's Autlogon.exe tool.

  • After running your script once, What happens if you log off, log on, then reboot?
    – Moab
    Oct 14, 2012 at 3:09
  • Can you see my edits above? Note that since I'm executing the script remotely "I" cannot necessarily log off. You have a good question, one that I'm not sure I'll be able to answer unless there's a utility where I can non-interactively log off and log on.
    – JohnZaj
    Oct 14, 2012 at 6:15
  • The plot thickens! hmmmm.
    – Moab
    Oct 14, 2012 at 16:18
  • I'm really hoping for an answer here so I can sleep at night. I really think this would get the attention it needed if it were on Stack Overflow, may just keep entering dupes on SO until the Admin gives up and lets it fly there
    – JohnZaj
    Dec 2, 2012 at 17:20
  • Did you tried it Run as Admin?
    – avirk
    Dec 3, 2012 at 15:13

4 Answers 4


Storing login/password in registry in plain text isn't good idea... I want to recommend you look at LogonExpert tool

  • I agree. Actually, the whole idea of Autologon isn't a 'good idea' either...Its meant for Kiosk situations where the system is locked down well from user's ability to do anything malicious. In other words, even if they can get to the clear text credentials, the credentials shouldn't take them very far. I've looked at logonexpert before. I believe there was a limitation, but I'll double check. Thanks!
    – JohnZaj
    Feb 18, 2013 at 4:40
  • +1 because this actually is the only tool that has worked for me / solved this particular problem.
    – JohnZaj
    Feb 19, 2013 at 4:40

Seems to be something with PsExec.
Read this question and see if any of solutions there helps you:
How do I change automatic logon via Script or Command Line?

  • I'll try the reg file approach I suppose. However note that this is not an issue for Winxp
    – JohnZaj
    Dec 7, 2012 at 3:31
  • reg file approach results in same behavior: it is missing both the "1" for AutoAdminLogon, and also the DefaultPassword key. If I then logoff, execute the same reg file the same way, then log back in, it is intact as I intended
    – JohnZaj
    Dec 7, 2012 at 4:28
  • i was talking about the autologin tool...reg file is going to be same..moreover, try to avoid PsExec..something sounds fishy there...instead try windows startup scripts: serverfault.com/questions/57798/… Dec 7, 2012 at 13:09
  • PsExec is not the culprit. Same behavior occurs with it taken out of the picture
    – JohnZaj
    Feb 18, 2013 at 4:42
  • PsExec merely runs the file as another user; basically the same as runas but with additional features (run as SYSTEM, run on remote computer). Manually logging in and running as any user would do the same thing.
    – Bob
    Feb 18, 2013 at 5:15

tahocannan led me to LogonExpert. With LogonExpert, I can install it silently, set up Auto Logon with it, then (remotely) kill windows' LogonUI.exe process, then reboot. The result: automatically logged in. I then immediately uninstall LogonExpert, then execute commands interactively in the guest machine.

I believe killing the native-Windows "LogonUI.exe" process is the key here. Occasionally, I would get the same result with LogonExpert where after setting up Auto Logon, a reboot would not result in being logged in automatically as desired. By ending LogonUI.exe, it forces a re-load of LogonExpert's library. Then the reboot will work


I believe this happens because the first time you set AutoAdminLogon = 1 there is also another registry value in Windows 7 called AutoLogonCount which is set to 0. If Windows sees this value set to 0 in the registry when it boots up it will disable AutoAdminLogon and this is why when you reboot you are not able to auto logon. If you delete AutoLogonCount from the registry at the same time you set your AutoAdminLogon to 1, then you should be ok after reboot.

While the idea of autologon is understood to be unsafe for regular desktop use, autoLogon is very useful for special computers, such as kiosks or computers attached to a demo display or monitoring devices where software needs to load automatically after booting up.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .