Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Computer Lock


  • Please log in to reply
62 replies to this topic
Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
This script will lock the screen preventing anyone accessing your PC once the lock has been activated.

As soon as the script starts you will be prompted to set your password. This password will be used to unlock the screen.

When the lock is activated a dialogue will appear prompting you for your password. If you enter a wrong password then a message box will appear for five seconds saying the password is wrong and then the password dialogue will appear again. The screen will grey out whilst the screen is locked but will still be transparent. The task bar will be hidden.

If you forget the password while the computer is locked the press Alt+X to unlock it. To reset all of the settings to blank press Alt-R.

You can activate the lock manually through the tray menu. The lock can also be set to come on automatically after a certain amount of idle time like a screen saver does. Select the time setting from the "Auto-Activate" menu on the tray.

All of the settings are stored in a file called "lock" located on c:\. The password stored in this file is encrypted thanks to Rajats RC4 encryption script.

Posted Image


;-------------------------Instructions-------------------------
;
;Alt X = Unlock Screen
;Alt R = Reset Password
;
;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, Status

IfNotExist, %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, Hours

Minutes=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/60000

If mins > 3
    Menu, TimerOptions,Check, %mins% mins

If mins = 3
    Menu, TimerOptions,Check, 3 Hours

If mins = 2
    Menu, TimerOptions,Check, 2 Hours

Menu, Tray, add, Lock
Menu, Tray, Default, Lock
Menu, Tray, add, Change Password, PassChange
Menu, TimerOptions, add, Disable
Menu, Tray, add, Auto-Activate, :TimerOptions


IniRead, autoStatus, %homeDrive%\lock, autoactivate, Status, 0

If autoStatus=1
    SetTimer, Timer, on

If 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, Off

Hotkey, Tab, Off
Hotkey, !Tab, Off
Hotkey, !F4, Off
Hotkey, LWin, Off
Hotkey, RWin, Off
Hotkey, AppsKey, Off
Hotkey, ^Escape, Off

Hotkey, 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, Password

If Password=
    Gosub, SetPassword
Return

PassChange:
  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, Disable

   Menu, TimerOptions, Enable, 3 Hours
   Menu, TimerOptions, Enable, 2 Hours
   Minutes=60
   Loop,12
   {
     Menu, TimerOptions, Enable, %Minutes% mins
     Minutes-=5
   }
 }

Auto-Activate:
Return


Hours:
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
 Return


Timer:

 ;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
 }
Return


Lock:

 lockstate=1

 IniRead, Password, %homeDrive%\lock, Password, Password

 If Password=Error
   IniWrite, `n, %homeDrive%\lock, Password, Password

 If 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, On

 Hotkey, Tab, On
 Hotkey, !Tab, On
 Hotkey, !F4, On
 Hotkey, LWin, On
 Hotkey, RWin, On
 Hotkey, AppsKey, On
 Hotkey, ^Escape, On

 Hotkey, NumpadUp, On
 Hotkey, NumpadDown, On
 Hotkey, NumpadLeft, On
 Hotkey, NumpadRight, On

 WinHide, 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, 600

 InputBox, Password, Enter Password Below, , hide ,250,100

 If ErrorLevel <> 0
 {
   Gosub, beginning
 }
 Else
 {
   IniRead, encryptedpass, %homeDrive%\lock, Password, Password

   If (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
   }
 }
Return

CloseTaskmgr:
 SetTimer, CloseTaskmgr, off
 Process, Wait, taskmgr.exe, 4
 Process, Close, taskmgr.exe
 SetTimer, CloseTaskmgr, on
return

DisableOK:
 Control, Disable, , OK, Error (%Timeout%)
Return

InputOnTop:
 Control, Disable, , Cancel, Enter Password Below
 WinSet, AlwaysOnTop, On, Enter Password Below
 SetTimer, InputOnTop, Off
Return

MsgBoxTimeout:
 oldTimeout=%Timeout%
 Timeout-=1
 WinSetTitle, Error (%oldTimeout%), , Error (%Timeout%)
 If Timeout = 0
   SetTimer, MsgBoxTimeout, off
Return

!x::
 Exit:
 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, Fast

 if lockstate=0
   goto, lock
 WinShow, ahk_class Shell_TrayWnd
 Reload

Left::
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
Return

Confirm:
 Gui, Submit
 IniWrite, 0, %homeDrive%\lock, SetPassword, True
 IniRead, encryptedpass, %homeDrive%\lock, Password, Password

 If (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_____________________________________ 


Mon
  • Members
  • 12 posts
  • Last active: Sep 07 2005 11:25 AM
  • Joined: 21 Aug 2005
Really nice script, I always wanted lock with nice simple interface like this!
Thanks!!

Mon :D

daonlyfreez
  • Members
  • 995 posts
  • Last active: Jan 23 2013 08:16 AM
  • Joined: 16 Mar 2005
What can I say, really nice! Works like a charm... 8) (on 2k)...

I will try to break it, however :p ...
Posted Image mirror 1mirror 2mirror 3ahk4.me • PM or Posted Image

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Thanks :)

I wrote it to keep my younger brother and his friend off the computer when I'm away from it :twisted:

I will try to break it, however


Have you managed to break it yet? :)

  • Guests
  • Last active:
  • Joined: --
hello 2gether.

very nice script, but easy to break :(

i can open the taskmanager (strg+shift+esc) and i can kill the process. please disbale the taskmanager somehow :)

thx!

aarondellis
  • Members
  • 57 posts
  • Last active: Feb 11 2013 02:18 PM
  • Joined: 15 Aug 2005
strg is ctrl (control)???

EDIT:
Pardon my ignorance! Yes "strg" is "ctrl". This only works with right control button on my laptop though.

Thanks!

Invalid User
  • Members
  • 447 posts
  • Last active: Mar 27 2012 01:04 PM
  • Joined: 14 Feb 2005
To prevent a script from being closed, I used a script(its here on the forum, but i coulnt find it) that looked for the task manager to appear, when it did it monitored the text selected in the app, and process list. it it matched that of the script it closed the window, so it leaves the task manager functional until your select script is highlighted. If you do find it, use caution as it required a reboot when I ran it.
my lame sig :)

ShadowWraith
  • Guests
  • Last active:
  • Joined: --
I'm still new to these things but shouldn't something like the following solve any problems with attempts to open the Task manager?

!^Delete::
WinWaitActive Windows Task Manager
WinKill Windows Task Manager
Return

^+Esc::
WinWaitActive Windows Task Manager
WinKill Windows Task Manager
Return

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
AutoHotkey can't block Ctrl-Alt-Del. In general, that is very hard to do (though there might be a solution involving RegEdit, Group Policy Editor, or something at the driver-level).

ShadowWraith
  • Guests
  • Last active:
  • Joined: --
Was wandering because it's not really blocking Ctrl-Alt-Del, just waiting for it to open the task manager and closing it before you can really do anything with it.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
You're right: Since all the script does is watch for Ctrl-Alt-Del, that will work. Apparently, the hook is able to see the ^!delete hotkey even though it can't block it.

leuce
  • Members
  • 28 posts
  • Last active: Sep 29 2014 01:27 PM
  • Joined: 17 May 2006

This script will lock the screen preventing anyone accessing your PC once the lock has been activated.

As soon as the script starts you will be prompted to set your password. This password will be used to unlock the screen.


Not on WXPSP2 running the latest stable version of AHK. The script doesn't prompt me for a password. Alt+R tells me that I'm about to reset the password, but it doesn't prompt me for a password.

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Do you mean that it doesn't prompt you to set a password or doesn't ask you for a password to unlock the screen?

I have just run the script and found that it was no longer asking me for a password to unlock the screen. I think I have fixed the problem now and I've updated the code in my first post with the fix.

leuce
  • Members
  • 28 posts
  • Last active: Sep 29 2014 01:27 PM
  • Joined: 17 May 2006

Do you mean that it doesn't prompt you to set a password or doesn't ask you for a password to unlock the screen?


It didn't even lock the screen. But now it works, with your changes made, thanks. I just can't get it to dismiss the Task Manager (but that's no problem for me at the moment).

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
I've just updated the script to close the task manager window when it appears.