I want a script to do following things automatically:
1. Restart Win10 as Admin.
2. Autologon as User, then restart Win10.
3. Autologon as Admin again.
Admin has blank password, User's password is "User".
Here is the my script:
call :Resume
goto %current%
goto :eof
:one
::Add script to Run key
REG ADD "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /v %~n0 /d %~dpnx0 /f
echo two >%~dp0current.txt
echo -- Section one --
echo "set registry to autologon as User"
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d User /f
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d User /f
pause
shutdown -r -t 5
goto :eof
:two
echo three >%~dp0current.txt
echo -- Section two --
echo "Autologon as User"
pause
REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d Administrator /f
REG DELETE "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /f
pause
shutdown -r -t 5
goto :eof
:three
echo -- Section three --
pause
echo "Autologon as Admin again"
pause
goto :eof
:resume
if exist %~dp0current.txt (
set /p current=<%~dp0current.txt
) else (
set current=one
)
When User try to change the DefautUserName from User to Admin and delete the DeFaultPassword in section 2, It get an "access denied" error.
Is there any way to solve this problem and make this script work? Thanks.