How to Automatically Login to Windows and Auto-Lock Workstation After Login?

Automatic logon and lock workstation

Setting up an automatic login in Windows also comes with a great responsibility to safeguard the user account from unauthorized use. After configuring automatic login to your user account, you may also want to set it to lock the workstation immediately at login.

The very reason of setting up automatic login is to avoid typing your credentials or your PIN if you’ve setup one. So, what’s the point of locking the workstation after logging in to your user account?

There are situations where it may be necessary. Many folks do this. Turn on the computer and come back again after a couple of minutes or so. In the meantime, the system would log in to your account, lock the workstation, run all the startup tasks & programs and get things initialized for you. When you come back, just type in your password and start using the system.

Here is another case where this is needed:

Our IT department has begun pushing out periodic Automated Updates overnight which subsequently reboot my workstation. The negative result of this process is my scheduled tasks, which require my network credentials, fail because I am no longer logged into the network when the task is scheduled to run. I leave my workstation logged in and locked (for security) when unattended.

Setting up Automatic Login to Your Account

Press WinKey + R, and type the following and press ENTER:

control userpasswords2

Uncheck Users must enter a user name and password to use this computer

Automatic logon and lock workstation

Click OK. When prompted, type in your user name and password and click OK.

The system is now set to automatically login to your user account. Next step is to create a Scheduled Task to lock the workstation automatically (optional, but more secure).

Automatically Lock Workstation During Logon

Start Task Scheduler, and click "Create Basic Task…" in the Actions pane.

Select "When I log on" in the Task Trigger dialog, and click Next.

Automatic logon and lock workstation

In the Action dialog, click "Start a program" and click Next

Automatic logon and lock workstation

In the next dialog, type the Program name as: C:\Windows\System32\rundll32.exe

In the "Add arguments" text box, type user32.dll, LockWorkStation



Automatic logon and lock workstation

So the command-line that would be executed is:

rundll32 user32.dll, LockWorkStation

The parameter is case-sensitive; Make sure you type exactly as given. Follow the on-screen instructions and finish the procedure.

Now you’ve created a task that locks the workstation immediately after login.

The same command can be run from the Startup folder using a shortcut, but items in the Startup folder are executed very late, which means your desktop would be exposed until the "lock workstation" shortcut kicks in. Whereas when you run it using Task Scheduler, the task is executed immediately after you type in your credentials and login is validated.

Startup folder

There are chances that the task may fail to run at logon, especially if the Scheduler service doesn’t start. As a fallback, you may create a shortcut to the rundll32.exe command-line above and place it in your Startup folder.

The Startup folder your your profile can be accessed by running the following shell: command from Run dialog:

shell:startup

Or by accessing the following folder directly.

C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Automatic logon and lock workstation

The above method(s) won’t provide you fool-proof security, but it’s a far better option than leaving your system unlocked when it’s unattended. If you’re extremely concerned about security, you won’t be using automatic logon in the first place.


One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support, my reader. It won't take more than 10 seconds of your time. The share buttons are right below. :)

About the author

Ramesh Srinivasan founded Winhelponline.com back in 2005. He is passionate about Microsoft technologies and he has been a Microsoft Most Valuable Professional (MVP) for 10 consecutive years from 2003 to 2012.

4 thoughts on “How to Automatically Login to Windows and Auto-Lock Workstation After Login?”

  1. When the computer boots from off state the lock screen appears but does not ask for password. You can just get in by clicking the lock screen. Yet when I run the Scheduled task or command line manually, the lock screen asks for a password like you would expect it to.

    Is there a solution to this problem?

  2. Problem in my case was that command: rundll32 user32.dll, LockWorkStation was running too earely . /Windows remembered credensials form autologon I don’t know how/.
    When i delayed in task scheduer about 20s.
    Everthing is ok

Leave a Comment