Bat Script to switch users for autologon RRS feed

  • Question

  • 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

    ::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

    shutdown -r -t 5
    goto :eof

    echo three >%~dp0current.txt
    echo -- Section two --
    echo "Autologon as User"

    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

    shutdown -r -t 5
    goto :eof

    echo -- Section three --

    echo "Autologon as Admin again"

    goto :eof

    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.

    • Moved by Bill_Stewart Monday, March 12, 2018 9:04 PM This is not free script conversion service
    Monday, January 29, 2018 7:08 AM

All replies