setlocal

:: Created by Noah Coad, http://coad.net, on 7/11/2011

echo.
echo   Windows Auto Login
echo ----------------------------------------------------------
echo Leave user name blank to clear auto login, Ctrl+C to cancel
echo Warning, password is stored in plain text in the registry!

:: Request username
set _username=%@regquery["HKLM_64\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName"]
echo Current auto login user name: %@if["%_username"=="-1",`<no auto login>`,%_username]
echo.

:: Request password and domain
input `User Name: ` %%_username
iff "%_username"=="" then
	set _password=
	set _domain=
	set _AutoAdminLogon=0
else
	set _AutoAdminLogon=1
	input `Password:  ` %%_password
	input `Domain (leave blank for workgroup): ` %%_domain
endiff

:: Use 64-bit registry if on a 64-bit machine
set bit=%@if[%_wow64==1,_64,]

:: Write registry settings
echo %@regset["HKLM%[bit]\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName",REG_SZ,%_domain] > nul
echo %@regset["HKLM%[bit]\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon",REG_SZ,%_AutoAdminLogon] > nul
echo %@regset["HKLM%[bit]\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName",REG_SZ,%_username] > nul
echo %@regset["HKLM%[bit]\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword",REG_SZ,%_password] > nul

:: Let user know of final result
echo.
iff "%_AutoAdminLogon"=="1" then
	echo Auto Login set for user: %_username
else
	echo Auto Login settings cleared `<no auto login>`
endiff