How-To: Lock Your Computer and Still See Desktop (AutoHotKey)
by Omni on Mar.23, 2009, under How-To Guides, Useful Programs
You may be paranoid about somebody else using your computer, and so to combat that, you just Switch Users and leave your computer on the log in screen. Also, you may have it set to go back to the log in screen once the screen saver kicks in, just for those times you forgot to log out. While this may be useful most of the times, it may not always cut it. What if you’re running some sort of intense process (like video encoding/conversion, for example) that you don’t necessarily need to interact with, but you just need to see how far it has progressed? Logging in every time you want to check that is a waste of time and energy, as, since the computer is busy with whatever it is processing, the login will be extremely slow and laggy.
On the other hand, if you simply don’t like the interface of the Window’s login screen (for some reason), or simply can’t access it easily, then this solution might be for you. My computer suddenly decided to stop letting me log out or even shut down the computer through regular means, so I had to resort to finding my own solutions. (It just freezes on the “Windows is shutting down” blue screen, if anybody has any idea why it may do these, leave a comment.)
I came across another AutoHotKey script that locks your computer with a password after either a certain amount of time, or if you give it the lock command. By lock, what it does is it places a white transparent cover over your whole screen and has an “Input Password” box in the middle. The AutoHotKey source is at the bottom of this post. For more information about how to use AutoHotKey, read the previous post on How to Control iTunes Remotely. Keep reading for the guide on how to use this computer locking script.
- Visit the AutoHotKey website and download the latest version, and install it (if it is not already installed on your system).
- Once installed, open up a new text document (NotePad works perfectly) and copy/paste the code given at the end of this post into the document.
- Save the file with the extension of .ahk (deleting the .txt, if it’s there). So, for example, your file may be called “autolock.ahk”.
- Confirm that it is working by double clicking on itunes.ahk (or whatever you named your script), and you should see a lock icon appear in the taskbar.
- If it is running for the first time, it will ask you to set your password.
- If you want to add the AHK script to run on startup (so that you don’t have to manually load it every time you turn on your computer), right click on your .ahk file, and go to Create Shortcut.
- Assuming you are running Windows XP, place the shortcut you just created here: “C:\Documents and Settings\<User>\Start Menu\Programs\Startup”. For future reference, any shortcut you place here will automatically load upon startup. You can place as many shortcuts as you want, but just remember that your startup time will slow down depending on how many programs you have running on startup.
- You are good to go! Check out the available hotkeys that you can use for AutoLock below. These are there just so that you don’t get locked out of your own computer if you forget your password. Most people will be deterred by the “Input Password” box alone, and probably won’t try different key combinations (and accidentally stumble across these). You can now successfully lock your computer while seeing how far a process might be, like ripping a DVD, etc, and not have to log in. If you want to minimize all windows when it locks (just so that if you leave anything with sensitive information open by mistake, it will be hidden when the computer locks), find the line entitled “Minimize all windows” in the code below, and remove the semicolon from the line below. So, the line that no longer has a semicolon should be the “Send #d” line.
- Alt L = Lock Screen
- Alt X = Unlock Screen
- Alt R = Reset Password
- Alt Q = Quit
;————————-Instructions————————-
;
;Alt L = Lock Screen
;Alt X = Unlock Screen
;Alt R = Reset Password
;Alt Q = Quit Program
;
;Use right click menu to set other options
;
;————————Requirements———————–
;
;Only tested on Windows XP
;
;Reasonably current version of Autohotkey
;
;———————————————————————lockstate=0
;Creates Black Password on first run
IfNotExist, %homeDrive%\lock
FileAppend,
(
[Password]
Password=
), %homeDrive%\lock;Creates GUI for Changing Password
Gui, Add, Text, x6 y10 w180 h20, Set your Password below-
Gui, Add, Text, x6 y40 w180 h20 , Old Password
Gui, Add, Edit, x6 y60 w180 h20 vpass0,
Gui, Add, Text, x6 y90 w180 h20, New Password
Gui, Add, Edit, x6 y110 w180 h20 vpass1,
Gui, Add, Text, x6 y140 w180 h20 , Confirm New Password
Gui, Add, Edit, x6 y160 w180 h20 vpass2,
Gui, Add, Button, x86 y190 w100 h30 gConfirm, Confirm;checks idle time every minutes
SetTimer, Timer, 60000;Timer Starts off disabled
IfNotExist, %homeDrive%\lock
IniWrite, 0, %homeDrive%\lock, autoactivate, StatusIfNotExist, %homeDrive%\lock
IniWrite, 900000, %homeDrive%\lock, autoactivate, milliSeconds;Creates Menu’s
Menu, Tray, Icon , %SystemRoot%\system32\SHELL32.dll, 48
Menu, Tray, NoStandard
Menu, TimerOptions, add, 3 Hours, Hours
Menu, TimerOptions, add, 2 Hours, HoursMinutes=60
Loop,12
{
Menu, TimerOptions, add, %Minutes% mins, Minutes
Minutes-=5
};Checks/Enables/Disables menu items based on status of timer
IniRead, ms, %homeDrive%\lock, autoactivate, milliSeconds
SetFormat, Float, 0.0
mins:=ms/60000If mins > 3
Menu, TimerOptions,Check, %mins% minsIf mins = 3
Menu, TimerOptions,Check, 3 HoursIf mins = 2
Menu, TimerOptions,Check, 2 HoursMenu, Tray, add, Lock
Menu, Tray, Default, Lock
Menu, Tray, add, Change Password, PassChange
Menu, TimerOptions, add, Disable
Menu, Tray, add, Auto-Activate, :TimerOptionsIniRead, autoStatus, %homeDrive%\lock, autoactivate, Status, 0
If autoStatus=1
SetTimer, Timer, onIf autoStatus=0
{
SetTimer, Timer, off
Menu, TimerOptions, Disable, 3 Hours
Menu, TimerOptions, Disable, 2 Hours
Minutes=60
Loop,12
{
Menu, TimerOptions, Disable, %Minutes% mins
Minutes-=5
}
Menu, TimerOptions,Rename, Disable, Enable
}Menu, Tray, add, Exit
;Enables All Blocked Keys
Hotkey, Left, Off
Hotkey, Right, Off
Hotkey, up, Off
Hotkey, down, OffHotkey, Tab, Off
Hotkey, !Tab, Off
Hotkey, !F4, Off
Hotkey, LWin, Off
Hotkey, RWin, Off
Hotkey, AppsKey, Off
Hotkey, ^Escape, OffHotkey, NumpadUp, Off
Hotkey, NumpadDown, Off
Hotkey, NumpadLeft, Off
Hotkey, NumpadRight, Off;If password isn’t set then you will be prompted for it on startup
IniRead, Password, %homeDrive%\lock, Password, Password
If Password=Error
IniWrite, `n, %homeDrive%\lock, Password, PasswordIf Password=
Gosub, SetPassword
ReturnPassChange:
Gosub, SetPassword
Return;——————————————————————-
;Disables/Enables Menu items and Timer
Disable:
If A_ThisMenuItem=Disable
{
IniWrite, 0, %homeDrive%\lock, autoactivate, Status
SetTimer, Timer, off
Menu, TimerOptions,Rename, Disable, Enable
Menu, TimerOptions, Disable, 3 Hours
Menu, TimerOptions, Disable, 2 Hours
Minutes=60
Loop,12
{
Menu, TimerOptions, Disable, %Minutes% mins
Minutes-=5
}
}If A_ThisMenuItem=Enable
{
IniWrite, 1, %homeDrive%\lock, autoactivate, Status
SetTimer, Timer, on
Menu, TimerOptions,Rename, Enable, DisableMenu, TimerOptions, Enable, 3 Hours
Menu, TimerOptions, Enable, 2 Hours
Minutes=60
Loop,12
{
Menu, TimerOptions, Enable, %Minutes% mins
Minutes-=5
}
}Auto-Activate:
ReturnHours:
Minutes:Menu, TimerOptions, UnCheck, 3 Hours
Menu, TimerOptions, UnCheck, 2 Hours
Minutes=60
Loop,12
{
Menu, TimerOptions, UnCheck, %Minutes% mins
Minutes-=5
}Menu, TimerOptions,ToggleCheck, %A_ThisMenuItem%
StringLeft, mins,A_ThisMenuItem, 2;Calculates milliseconds to wait based on timer option chosen
If mins=2
milliSeconds=7200000
If mins=3
milliSeconds=10800000
milliSeconds:=mins*60000
IniWrite, %milliSeconds%, %homeDrive%\lock, autoactivate, milliSeconds
ReturnTimer:
;If more than X minutes has passed then lock the screen
IniRead, milliSeconds, %homeDrive%\lock, autoactivate, milliSeconds
If A_TimeIdlePhysical > %milliSeconds%
{
SetTimer, Timer, off
Gosub, Lock
}
ReturnLock:
lockstate=1
;Minimize all windows
;Send #dIniRead, Password, %homeDrive%\lock, Password, Password
If Password=Error
IniWrite, `n, %homeDrive%\lock, Password, PasswordIf Password=
{
Gosub, SetPassword
Return
};Blocks all hotkeys which could be used to unlock the screen
Hotkey, Left, On
Hotkey, Right, On
Hotkey, up, On
Hotkey, down, OnHotkey, Tab, On
Hotkey, !Tab, On
Hotkey, !F4, On
Hotkey, LWin, On
Hotkey, RWin, On
Hotkey, AppsKey, On
Hotkey, ^Escape, OnHotkey, NumpadUp, On
Hotkey, NumpadDown, On
Hotkey, NumpadLeft, On
Hotkey, NumpadRight, OnWinHide, ahk_class Shell_TrayWnd
WinGetPos, , , Width, Height, ahk_class Progman
SplashTextOn, %Width%, %Height%, Lock SCREEN, SCREEN is locked
WinSet, Transparent, 100, Lock SCREEN;——————————————————————
;Begins Locking of Screen
beginning:
lockstate=1
SetTimer, InputOnTop, 500
SetTimer, CloseTaskmgr, 600InputBox, Password, Enter Password Below, , hide ,250,100
If ErrorLevel <> 0
{
Gosub, beginning
}
Else
{
IniRead, encryptedpass, %homeDrive%\lock, Password, PasswordIf (Password = RC4(encryptedpass,RC4Pass))
{
SplashTextOff
WinShow, ahk_class Shell_TrayWnd
Reload
}
Else
{
;System Modal = 4096
;Icon Hand = 16
;OK =0
Timeout=5
SetTimer, DisableOK, 100
SetTimer, MsgBoxTimeout, 1000
MsgBox, 4112, Error (%Timeout%), Invalid Password, 6
Gosub, beginning
}
}
ReturnCloseTaskmgr:
SetTimer, CloseTaskmgr, off
Process, Wait, taskmgr.exe, 4
Process, Close, taskmgr.exe
SetTimer, CloseTaskmgr, on
returnDisableOK:
Control, Disable, , OK, Error (%Timeout%)
ReturnInputOnTop:
Control, Disable, , Cancel, Enter Password Below
WinSet, AlwaysOnTop, On, Enter Password Below
SetTimer, InputOnTop, Off
ReturnMsgBoxTimeout:
oldTimeout=%Timeout%
Timeout-=1
WinSetTitle, Error (%oldTimeout%), , Error (%Timeout%)
If Timeout = 0
SetTimer, MsgBoxTimeout, off
Return!x::
SplashTextOff
WinShow, ahk_class Shell_TrayWnd
ReloadExit:
WinShow, ahk_class Shell_TrayWnd
ExitApp!r::
MsgBox,4,, Are you sure you want to reset the Password?
FileDelete, %homeDrive%\lock
Return!l::
Listvars
Winwait, %A_ScriptFullPath%
Winhide, %A_ScriptFullPath%
SetTitleMatchMode, Fastif lockstate=0
goto, lock
WinShow, ahk_class Shell_TrayWnd
ReloadLeft::
right::
up::
down::Tab::
!Tab::
!F4::
LWin::
RWin::
Appskey::
^Escape::NumpadUp::
NumpadDown::
NumpadLeft::
NumpadRight::Return
SetPassword:
IniRead, Password, %homeDrive%\lock, Password, Password
Gui, Show, x361 y359 h230 w198, Change Password
If Password=
Control, Disable, ,Edit1, Change Password
ReturnConfirm:
Gui, Submit
IniWrite, 0, %homeDrive%\lock, SetPassword, True
IniRead, encryptedpass, %homeDrive%\lock, Password, PasswordIf (RC4(encryptedpass,RC4Pass) != pass0)
{
Gui, Show
MsgBox, Old Password is incorrect
Return
}
If (pass1=”" or pass2 =”")
{
Gui, Show
MsgBox, new Password cannot be blank
Return
}
If pass1=%pass2%
{
encryptedpass:=RC4(pass1,RC4Pass)
IniWrite, %encryptedpass%, %homeDrive%\lock, Password, Password
}
Else
{
Gui, Show
MsgBox, Passwords do not match!
Return
}
Return;___RC4 Encryption by Rajat_____________________________________
RC4(RC4Data,RC4Pass)
{
global RC4Result
ATrim = %A_AutoTrim%
AutoTrim, Off
BLines = %A_BatchLines%
SetBatchLines, -1
StringLen, RC4PassLen, RC4Pass
Loop, 256
{
a := A_Index – 1
Transform, ModVal, Mod, %a%, %RC4PassLen%
ModVal ++
StringMid, C, RC4Pass, %ModVal%, 1
Transform, AscVar, Asc, %C%
Key%a% = %AscVar%
sBox%a% = %a%
}
b = 0
Loop, 256
{
a := A_Index – 1
TempVar := b + sBox%a% + Key%a%
Transform, b, Mod, %TempVar%, 256
T := sBox%a%
sBox%a% := sBox%b%
sBox%b% = %T%
}
StringLen, DataLen, RC4Data
RC4Result =
i = 0
j = 0
Loop, %DataLen%
{
TmpVar := i + 1
Transform, i, Mod, %TmpVar%, 256
TmpVar := sBox%i% + j
Transform, j, Mod, %TmpVar%, 256
TmpVar := sBox%i% + sBox%j%
Transform, TmpVar2, Mod, %TmpVar%, 256
k := sBox%TmpVar2%
StringMid, TmpVar, RC4Data, %A_Index%, 1
Transform, AscVar, Asc, %TmpVar%
Transform, C, BitXOr, %AscVar%, %k%
IfEqual, C, 0
C = %k%
Transform, ChrVar, Chr, %C%
RC4Result = %RC4Result%%ChrVar%
}
AutoTrim, %ATrim%
SetBatchLines, %BLines%
Return RC4Result
}
;___RC4 Encryption by Rajat_
Note: I did not write this script, I found it on a forum a long time ago. I do not claim to be the author, and if I could find the source, I would link to it. If anybody knows the source of this, please leave the link as a comment and I’ll be sure to credit the proper source.
Did you like what you read? Be sure to get the latest posts emailed straight to you or subscribe to our RSS feed for the latest posts.
April 2nd, 2009 on 8:08 pm
Usually for me, when Windows hangs on the “Windows is shutting down” screen, it’s trying to do a system restore save point and if you haven’t done that in a while, then it takes FOREVER to do it. Try disabling system restore or just leave it like that overnight and *hopefully* it’ll resolve.
April 5th, 2009 on 2:28 pm
The first time I ran it, there was an error on line 396, the quotations are illegal characters so just change’em to uh, straight quotations? I don’t know what they’re called
April 5th, 2009 on 2:33 pm
Hmm, I have two monitors, and the lock seems to only some of my monitor, do you know which line sets the screen lock size?
April 5th, 2009 on 3:54 pm
changing to straight quotations is what you’d want to do.
as for the two monitors, i also have 2 monitors and noticed the same thing (transparency doesn’t cover full screen) but the other screen is still locked. It’s just an aesthetics thing so it doesn’t really matter to me, but if it does for you, it probably has to do with the line
SplashTextOn, %Width%, %Height%, Lock SCREEN, SCREEN is locked
WinSet, Transparent, 100, Lock SCREEN
but I have no idea what to change.