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

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_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinlogonAutoAdminLogon)  

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.

Solution:

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_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinlogon]"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 "HKLMSoftwareMicrosoftWindows NTCurrentVersionWinlogon" /v AutoAdminLogon /t REG_SZ /d 1 /fREG ADD "HKLMSoftwareMicrosoftWindows NTCurrentVersionWinlogon" /v DefaultDomainName /t REG_SZ /d domainname /fREG ADD "HKLMSoftwareMicrosoftWindows NTCurrentVersionWinlogon" /v DefaultUserName /t REG_SZ /d Administrator /fREG ADD "HKLMSoftwareMicrosoftWindows NTCurrentVersionWinlogon" /v DefaultPassword /t REG_SZ /d Pa$$w0rd /f

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