Take a look at this: Auto Logon and Lock

Auto Logon to Windows and immediately Lock Workstation (Safe Mode protected too)

Auto Logon & Lock is a small utility that enables your Windows PC to automatically logon to a user account on boot and then lock the desktop so a password is still required. Some of the reasons you might want to do this are: Faster boot time. The additional post-logon start up items are also started after Windows boots. Which means when you press the power button on your PC and come back after a few minutes, its completely booted up. No need to wait for additional software to load after you logon. Automatically resume downloads etc. when your PC reboots due to a power failure or crash. On XP you could do this by installing the application as a system service. In Vista and 7, Session 0 Isolation makes using a system service a pain, not to mention it's insecure. Just put your applications in the regular Windows Start Up folder and they will be launched after the auto logon. It password protects Safe Mode as well. Existing auto logon methods leave Safe Mode unprotected. It locks the desktop before Explorer is started. Other methods auto-lock using an autorun/start up entry which leave the PC logged on and unlocked until the autorun entries are executed (which can even take several minutes).

I haven't tried it myself, but it looks like it does what you want...


I managed to lock the PC immediately on startup while loading windows/startup items in the background. This works with Windows editions that has group policy editor.

Step 1: Open notepad, then paste this code:

WScript.CreateObject("WScript.Shell").Run("rundll32 user32.dll,LockWorkStation")

Step 2: Click File>Save As and in Save as type dropdown menu, choose All Files

Step 3: In the File Name field, enter LockWorkStation.vbs and save the file to C:\Users\YourUserName\Documents

Step 4: Hit WindowsKey+R, type regedit and press ENTER

Step 5: Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

Step 6: Right Click on a blank space and click New> DWORD (32-bit) Value and press ENTER

Step 7: Double click the newly created REG_DWORD file. In the Value name type RunLogonScriptSync and in the Value data type1 and then press ENTER

Step 8: Hit WindowsKey+R, type gpedit.msc and press ENTER

Step 9: Under Computer Configuration, go to Administrative Templates > System > Logon then Double Click Run these programs at user logon

Step 10: Click Enabled, and on Items to run at logon click Show...

Step 11: Type C:\Users\YourUserName\Documents\LockWorkStation.vbs and click OK repeatedly until all windows are closed

Step 12: Hit WindowsKey+R and type control.exe userpasswords2 then press ENTER

Step 13: Uncheck Users must enter a user name and password to use this computer. then click OK (type in your password if it prompts to do so)

Step : Restart your PC.

Now whenever you start your PC, the .vbs script will run first before anything else. This will ensure that your PC is locked before the desktop appears.

Note: You can change C:\Users\YourUserName\Documents\ to wherever you want to store your script.


You can implement this as a windows task scheduled to be performed at login:

Run program rundll32.exe With arguments user32.dll,LockWorkStation

It works on my XP and 7, however it won't work on Windows 8/8.1


I used to do this on my home computer (not any more). It involves just two simple steps.

  1. Set Windows to automatically log in to your account upon start-up (this will load all the start-up programs and take you to the desktop).
  2. Include a shortcut in your personal Startup folder (or the registry's Run key) to lock the computer, either wih the following command or with nircmd utility.

    rundll32.exe user32.dll,LockWorkStation
    

Since most start-up programs are loaded in parallel, your computer will be locked almost immediately upon being automatically logged into. There's minimum concern of someone snooping in and stopping the lock.

However, if you need to ensure the computer is locked as soon as possible, follow the order in this article (avoid RunOnce as this is deleted after run, unless you can place a counter-script somewhere else to add it back).
I found this KB article which lists the order proper for older versions of Windows, but I can't find an official equivalent for Windows 7.