I am looking for a program that automatically logs into Windows when I turn the computer on, and then locks it straight away.

ie: I turn my computer on > I am automatically logged in if there is inactivity for a few seconds > The computer is then locked (ie. Win + L).


  • free
  • only logs in if there is inactivity for a user-defined time (less than 3 or so minutes)
  • locks the computer, Windows style, not its own style
  • runs on Windows 7 64 bit

I'm sure every single person reading this has had at least one time where they turn their computer on, and go away for a few minutes (maybe the toilet? :) and you returned to see you didn't login! You then had to login and wait for a few minutes to make sure all the startup programs open and, finally (!) you could start doing whatever you wanted to!

This program will help be avoid what I said above. It will ensure that the programs that should open on login, start opening as soon as the computer turns on (rather than waiting for me to come back, enter my password, and wait 5 minutes for them to start).

  • What does "inactivity" mean? Mouse, keyboard, joystick, MIDI, attach a USB stick, ...? Jul 16, 2016 at 8:59
  • @ThomasWeller basically when the computer is completely idle. no mouse movement, keyboard keys, peripherals being used Jul 16, 2016 at 14:56
  • 2
    Related: superuser.com/q/352616/35237 Dec 11, 2017 at 9:04
  • @Tobias - that seems perfect! I'd be happy to mark that as an answer if you posted one! :) Feb 24, 2018 at 22:42

2 Answers 2


Do both the following:

  1. set up your account to auto-login: (below is quoted from that link)

    1. Click Start, type netplwiz, and then press Enter.
    2. In the User Accounts dialog box, click the account you want to automatically log on to.If it is available, clear the "Users Must Enter A User Name And Password To Use This Computer" check box.
    3. Click OK.
    4. In the Automatically Log On dialog box, enter the user’s password twice and click OK.

    This will start the Advanced User Accounts Access Panel, and allow you to switch on Windows' built-in auto-login function for that account. This is a built-in windows function, there isn't a time-out option to only initiate the login after a period of inactivity.

  2. With your favorite text editor, create a .cmd batch file (not .bat). The file name does not matter, I called mine autolock.cmd. The file should contain the following commands:

    timeout /t 10
    rundll32.exe user32.dll,LockWorkStation
  3. Move or copy it into your "All Users" startup folder. On Windows 8/10 you can easily navigate to the All Users startup folder in File Explorer by typing shell:common startup in the path field (the current user's startup folder is shell:startup).

Step 1 above logs you in automatically after every restart. The .cmd file then gets run a few seconds after login; it will wait for ten seconds, and then lock the workstation. If you don't want the lock to kick in, just press Ctrl+C to interrupt

  • Is there a Windows 10 alternative for this?
    – HippoDuck
    Nov 6, 2017 at 10:04
  • Updated to remove the dependency on 3rd party software. This can all be accomplished easily using native Windows commands. Mar 15, 2019 at 5:57
  • Very slick, helped me launch VMWare Workstation and VM, then lock computer. Sep 9, 2021 at 1:20

You should be able to use AutoHotkey (Free, open-source, Windows), something along the lines of:

Sleep, 60000  ; 60 seconds (change this depending on how long you want to wait)
Send #l       ; hold down the Windows key and then press the letter "l" -> lock Windows

compile the script into an EXE with ahk2exe and add it in startup.

  • 1
    Cool, but will this work before I login?? Or will I need to login and then this will work? Adding it to startup would mean after 60 seconds of being logged in, the computer will be locked Jul 15, 2014 at 15:52
  • 1
    You might want to see this. Apparently the AutoHotKey version you link to is out of date. Maybe that is why your answer on my minimizing question is not working? Jul 15, 2014 at 16:44
  • @ṧнʊß Yes it wouldn't get locked directly, but should be pretty quick if you get rid of the sleep. Thanks the link, I updated but still same issue :/ Jul 15, 2014 at 16:49
  • I meant I want to login automatically after a few minutes, and then lock immediately... Jul 16, 2014 at 10:35
  • Oh sorry, now I get it :) I'll leave the answer as it can be use as an alternative second step to energy number's answer, but yeah first step turn on auto login! Jul 16, 2014 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.