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.
1There probably isn't any way to do this. Have you considered hibernating instead of shutting down? – Harry Johnston – 2011-11-01T02:58:40.017
Yes. I don't like hibernating because some programs lose their network connection and I have to restart them anyways. – utapyngo – 2011-11-01T03:11:59.170
Which programs in detail? Have you tried to make the authors fix this problem? – Robert – 2011-11-01T12:41:21.290
@eye:I don't get it. So because you have to restart these programs, you decide you need to restart your whole machine?? Am I missing something? – surfasb – 2011-11-01T14:11:52.823
2@surfasb: one more reason is that it is faster to turn off and turn on my computer that dump 8 gigabytes of RAM and then read it back. – utapyngo – 2011-11-02T16:18:06.630
@surfasb another reason is that hibernating won't help a desktop that loses power unexpectedly. You can configure the BIOS to restart the computer when power is restored; but only services are restarted not any usermode applications. – Dan is Fiddling by Firelight – 2012-05-24T18:40:10.893
@DanNeely: Very good point. Not all desktops are hooked up to a UPS. – surfasb – 2012-06-01T15:32:13.720