 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Tue Sep 06, 2005 6:35 pm Post subject: Computer Lock |
|
|
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.
| Code: |
;-------------------------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_____________________________________
|
Last edited by Jon on Thu Nov 02, 2006 3:50 pm; edited 6 times in total |
|
| Back to top |
|
 |
Mon
Joined: 21 Aug 2005 Posts: 12
|
Posted: Tue Sep 06, 2005 9:43 pm Post subject: Nice!! |
|
|
Really nice script, I always wanted lock with nice simple interface like this!
Thanks!!
Mon  |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 745 Location: Berlin
|
Posted: Tue Sep 06, 2005 10:07 pm Post subject: |
|
|
What can I say, really nice! Works like a charm... (on 2k)...
I will try to break it, however ... _________________ (sorry, homesite offline atm) |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Fri Sep 09, 2005 5:31 pm Post subject: |
|
|
Thanks
I wrote it to keep my younger brother and his friend off the computer when I'm away from it
| Quote: | | I will try to break it, however |
Have you managed to break it yet?  |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Sep 27, 2005 10:04 am Post subject: |
|
|
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! |
|
| Back to top |
|
 |
aarondellis
Joined: 15 Aug 2005 Posts: 57
|
Posted: Tue Sep 27, 2005 12:34 pm Post subject: |
|
|
strg is ctrl (control)???
EDIT:
Pardon my ignorance! Yes "strg" is "ctrl". This only works with right control button on my laptop though.
Thanks! |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Tue Sep 27, 2005 1:06 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
ShadowWraith Guest
|
Posted: Sat Mar 11, 2006 10:38 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sun Mar 12, 2006 4:36 pm Post subject: |
|
|
| 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). |
|
| Back to top |
|
 |
ShadowWraith Guest
|
Posted: Tue Mar 14, 2006 11:05 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Mar 15, 2006 1:27 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
leuce
Joined: 17 May 2006 Posts: 23 Location: Johannesburg, ZA
|
Posted: Tue Jul 04, 2006 1:35 pm Post subject: Re: Computer Lock |
|
|
| Jon wrote: | 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. |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Tue Jul 04, 2006 2:31 pm Post subject: Re: Computer Lock |
|
|
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. |
|
| Back to top |
|
 |
leuce
Joined: 17 May 2006 Posts: 23 Location: Johannesburg, ZA
|
Posted: Tue Jul 04, 2006 3:13 pm Post subject: Re: Computer Lock |
|
|
| Jon wrote: | | 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). |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Tue Jul 04, 2006 6:54 pm Post subject: |
|
|
| I've just updated the script to close the task manager window when it appears. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|