How do I change automatic logon via Script or Command Line?

12

4

After deploying a Windows 7 image to Stand alone machines we run into the following problem.

If we set autologon to off then we have to log in manually and activate Windows and Office - the Keys are installed but the products are not activated. (These laptops are set as loan laptops so may not be used for months after they are imaged - grace period expired)

If we do set Autologon to on and run a script to activate the products on first logon - when they are network connected, then the machine will always log on to the account we have specified in the autologon.

I was wondering, is there a way to turn off autologon via a script?
It can be done manually by following the instructions in this post or via a registry key(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon)

I'm not sure how to manage this from the command line or a script if anyone could point me in the right direction it would be much appreicated.

Joe Taylor

Posted 2011-09-27T13:12:14.493

Reputation: 11 533

Answers

16

One can change the registry via a .reg file.

For example, create an autologin.reg file containing :

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"AutoAdminLogon"="1"
"DefaultUserName"="Administrator"
"DefaultPassword"="Pa$$w0rd"

Add DefaultDomainName if required, then just execute the file to get the values into the registry.

Or in a cmd script :

REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d domainname /f
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d Administrator /f
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d Pa$$w0rd /f

(Warning: I didn't test the above.)

harrymc

Posted 2011-09-27T13:12:14.493

Reputation: 306 093

Just execute it from a bat file? – Joe Taylor – 2011-09-30T10:10:40.147

Yes for the 2nd one, run as administrator. – harrymc – 2011-09-30T10:17:55.477

Calling a reg file from a bat file to run at first logon worked for me. – Joe Taylor – 2011-10-04T10:17:50.637

The data type for AutoAdminLogon should be REG_SZ and not REG_BINARY. – Irukandji – 2012-07-24T11:57:39.410

@baijiu: Well, I did warn that it was untested... Fixed now. – harrymc – 2012-07-24T13:16:03.213

Be sure to run the x64 reg.exe on x64 Windows. (set proc will display PROCESSOR_ARCHITECTURE=x86 in a WoW64 cmd.exe. In that case you'll need to run %SystemRoot%\SysNative\reg.exe.) – Kevin Smyth – 2014-03-25T20:35:51.907

1

Can't you just use sysprep /oobe? It will finalize your install and show the welcome screen on reboot.

Read what sysprep is and how sysprep works for more information.

Tamara Wijsman

Posted 2011-09-27T13:12:14.493

Reputation: 54 163

I use sysprep /oobe to prepare the image, we then deploy the image using WDS. When we do this with machines we join to the domain we never have this problem but when the machine is a stand alone machine it keeps the auto logon for some reason. – Joe Taylor – 2011-09-30T22:18:29.837

@JoeTaylor: That's generalization. What I meant was to run sysprep /oobe after deployment, so it'll leave the audit mode which WDS has put it in. This should get rid of the auto login settings, which are only intended to be present during the audit... – Tamara Wijsman – 2011-09-30T22:21:49.860

Will you still be able to specify the OOBE arguments - region, usernames, etc? – Joe Taylor – 2011-10-01T10:59:51.440

@JoeTaylor: Sorry, I don't know what you mean by that. I have seen the thing I describe as working, but don't know about customizing what you describe. I think region is configured as part of the unattended installation (it was like that when I used MDT, I don't know how to do this by command), the users can be added using something like net user /?. – Tamara Wijsman – 2011-10-01T16:57:15.463

0

Sysinternal's Autologon should be able to auto logon only once. That was a function when I've used it a while ago but I'm not seeing any details on whether it does that now.

music2myear

Posted 2011-09-27T13:12:14.493

Reputation: 34 957

I was hoping for something native to Windows 7 but thanks for the advice. – Joe Taylor – 2011-09-30T22:20:00.690

Does Autologon have command line options that I'm unaware of? – Tamara Wijsman – 2011-09-30T22:24:04.303

@JoeTaylor: It takes a simple net start webclient && copy \\live.sysinternals.com\Tools\Autologon.exe . to obtain it if you have an internet connection... :) – Tamara Wijsman – 2011-09-30T22:24:55.770