AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Desktop lock with USB key
Goto page 1, 2, 3  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Chavez



Joined: 20 Aug 2008
Posts: 256

PostPosted: Wed Aug 20, 2008 3:55 pm    Post subject: Desktop lock with USB key Reply with quote

I made this code for myself, it's not that advanced but works very well for me. I use it at home as i have classified information on my computer. This program does very well at defending it when I'm out for a coffee break.

So, here's how it works:

When you hit F8, your screen is filled with a black screen which says 'Locked'. All inputs will be blocked, and because alt+ctrl+del still works, i looped a taskkill for that. Every 200 milliseconds, the script checks if there's an 'I' drive. This is (at my computer) the USB drive when plugged it. If it finds the drive, it will check a file called 'key.txt' and compare it to the same file but then located in /WINDOWS/. If both file's content are identical to each other, it will unlock again.

So, in short: Your USB drive is the key to unlock your computer. You only have to type your password twice. Once in the windows dir, and once in the root of your USB drive.

Pretty neat idea eh? :3

Code:
#NoTrayIcon
SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79


F8::
Lock:
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, 000000
Gui, Font, CFF0000
Gui, Font,, Arial
Gui, Font, s128
Gui, Font, x0 y0
Gui, Add, Text, Locked, Locked
Gui, Show, x0 y0 h%VirtualScreenHeight% w%VirtualScreenWidth% , lock
SetTimer, checkkey, 200
return

checkkey:
driveget, drives, list, removable   ;list of removable drives
FileRead, localkey, C:\WINDOWS\key.txt
passkey=  ;filereadline will not overwrite passkey if there is an error
keyaccepted:=false   
loop, parse,drives
   {
   FileRead, passkey, %a_loopfield%:\key.txt
   if (passkey=localkey)
      {   
       Gui Destroy
       BlockInput off
       SetTimer, checkkey, off
       keyaccepted:=true
       break
      }
   }
if not keyaccepted
   {
    BlockInput on
   WinKill, Windows Task Manager
   Gui, Show, x0 y0 h%VirtualScreenHeight% w%VirtualScreenWidth% , lock   ;paints over any crack attempt
   }
return



I hope someone's helped with this, or that you found the idea interesting. Please make a small notice about me whenever you will release this to the public.
_________________
-Chavez.


Last edited by Chavez on Wed Dec 03, 2008 7:50 pm; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
Fry



Joined: 01 Nov 2007
Posts: 885

PostPosted: Wed Aug 20, 2008 4:01 pm    Post subject: Reply with quote

Heres my version so the user does not have to put the Screen width/height in

Pretty good script, i like it

Code:
F8::
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, 000000
Gui, Font, CFF0000
Gui, Font,, Arial
Gui, Font, s128
Gui, Font, x0 y0
Gui, Add, Text, Locked, Locked
Gui, Show, x0 y0 h%A_ScreenHeight% w%A_ScreenWidth% , lock
SetTimer, checkkey, 200
BlockInput on
GoSub checkkey
return

checkkey:
loop
{
FileReadLine, localkey, C:\WINDOWS\key.txt, 1
FileReadLine, passkey, I:\key.txt, 1
if passkey = %localkey%
{   
    Gui Destroy
    BlockInput off
    break
}
else
{
      WinKill, Windows Task Manager
   return
}
sleep, 200
}
return
Back to top
View user's profile Send private message
Chavez



Joined: 20 Aug 2008
Posts: 256

PostPosted: Wed Aug 20, 2008 4:05 pm    Post subject: Reply with quote

Fry wrote:
Heres my version so the user does not have to put the Screen width/height in

Pretty good script, i like it


I tried so many things today to make it work. I figured it'd be better if i prepared it like that, but i couldn't figure it out. Thanks for pointing me on the syntax there.
_________________
-Chavez.
Back to top
View user's profile Send private message MSN Messenger
Fry



Joined: 01 Nov 2007
Posts: 885

PostPosted: Wed Aug 20, 2008 5:12 pm    Post subject: Reply with quote

Your welcome, you could have posted in the Ask for help section, someone would have gladly helped you
Back to top
View user's profile Send private message
SoggyDog



Joined: 02 May 2006
Posts: 783
Location: Greeley, CO

PostPosted: Wed Aug 20, 2008 5:30 pm    Post subject: Reply with quote

Could this scan all USB ports for the Flash Drive rather than having a fixed drive location?
_________________

SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Thu Aug 21, 2008 2:16 pm    Post subject: Reply with quote

good program but i went looking for cracks

ctrl-alt-del, on my system frees the mouse but other input is still blocked. as i use a mouse gesture program deleting the block is then straight forward. possible fix would be to block input every loop iteration.
if i ctrl-alt-del, then hit esc before the task manager is killed, the task bar appears and remains. it's then easy to turn off the program with the tray icon. possible fixes - no tray icon, disable esc key (esc::return)
doesn't work on multiple monitors. use virtualscreen measurements instead of a_screenheight etc
don't see the point of having both SetTimer, checkkey and GoSub checkkey
changed script so any removable drive letter is accepted
Code:
#NoTrayIcon
SysGet, VirtualScreenWidth, 78
SysGet, VirtualScreenHeight, 79

esc::return

F8::
driveget, drives,list,removable   ;list of removable drives
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, 000000
Gui, Font, CFF0000
Gui, Font,, Arial
Gui, Font, s128
Gui, Font, x0 y0
Gui, Add, Text, Locked, Locked
Gui, Show, x0 y0 h%VirtualScreenHeight% w%VirtualScreenWidth% , lock
SetTimer, checkkey, 200
return

checkkey:
FileRead, localkey, C:\WINDOWS\key.txt
passkey=  ;filereadline will not overwrite passkey if there is an error
keyaccepted:=false   
loop, parse,drives
   {
   FileRead, passkey, %a_loopfield%:\key.txt
   if (passkey=localkey)
      {   
       Gui Destroy
       BlockInput off
       SetTimer, checkkey, off
       keyaccepted:=true
       break
      }
   }
if not keyaccepted
   {
    BlockInput on
   WinKill, Windows Task Manager
   Gui, Show, x0 y0 h%VirtualScreenHeight% w%VirtualScreenWidth% , lock   ;paints over any crack attempt
   }
return
Back to top
View user's profile Send private message
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Thu Aug 21, 2008 4:40 pm    Post subject: Reply with quote

Nice I like it.

The CTR+ALT+Delete on my PC (Vista) Dosn't get blocked because I have teh option of closing all aplictaions. I reconment you do somethign like this...
Code:

CTR::
ALT::

just for safty =D
_________________

I know i have 6 legs. It's cuz I'm special.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Chavez



Joined: 20 Aug 2008
Posts: 256

PostPosted: Thu Aug 21, 2008 4:45 pm    Post subject: Reply with quote

Thanks for patching it up guys, much appreciated. Specially Rodfell. It's a whole lot more secure now.
_________________
-Chavez.
Back to top
View user's profile Send private message MSN Messenger
krueger00



Joined: 14 Sep 2008
Posts: 10

PostPosted: Sun Sep 14, 2008 9:49 pm    Post subject: Reply with quote

PLEASE HELP ME

I keep getting error messages no matter what script it is.

They change for every script though and they don't make sense.

For this script it says:

---------------------------
New AutoHotkey Script.ahk
---------------------------
Error at line 21.

Line Text:    
Error: This line does not contain a recognized action.

The program will exit.
---------------------------
OK
---------------------------


Thanks in advance for any help.
Back to top
View user's profile Send private message
bonzybuddy



Joined: 13 Sep 2008
Posts: 3

PostPosted: Mon Sep 15, 2008 7:15 am    Post subject: suggestion Reply with quote

Nice script , i have a suggestion . you can script detectiong any removable drive for key not just drive I. if you wont then msg me i will post it. keep it up.
_________________
Give your folders a new look with Custom Folderwallpaper .it gives background of any wallpaper you choose.get it here
http://www.autohotkey.net/~bonzybuddy/custom%20folder%20wallpaper.rar
Back to top
View user's profile Send private message Send e-mail
Chavez



Joined: 20 Aug 2008
Posts: 256

PostPosted: Mon Sep 15, 2008 8:38 am    Post subject: Re: suggestion Reply with quote

bonzybuddy wrote:
Nice script , i have a suggestion . you can script detectiong any removable drive for key not just drive I. if you wont then msg me i will post it. keep it up.


That function has already been implemented by rodfell. I'll update my first post.
_________________
-Chavez.
Back to top
View user's profile Send private message MSN Messenger
n-l-i-d
Guest





PostPosted: Mon Sep 15, 2008 11:33 am    Post subject: Reply with quote

I cleaned up your code a bit (minimized the necessary reads, condensed some code... not tested though), settings in red

Code:
   #NoTrayIcon

   pcFilePath = C:\WINDOWS\key.txt
   usbFile = key.txt

   OnExit, DoExit

   lastUsbFilePath =
   SysGet, VirtualScreenWidth, 78
   SysGet, VirtualScreenHeight, 79
Return

F8::
   Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
   Gui, Color, 000000
   Gui, Font, x0 y0 cFF0000 s128, Arial
   Gui, Add, Text, Locked, Locked
   Gui, Show, x0 y0 h%VirtualScreenHeight% w%VirtualScreenWidth% , lock
   SetTimer, DoCheckKey, 200
Return

DoCheckKey:
   ; get pc key
   FileRead, pcKey, %pcFilePath% ; read the pc key
   IfEqual, ErrorLevel, 1, Gosub, DoBlock ; there was an error reading the pc file, block
   ; get usb key
   If not lastUsbFilePath ; if we don't have the usb file path yet...
   {
      DriveGet, allDrives, List, Removable ; get list of removable drives
      Loop, Parse, allDrives ; loop thru all removable drives
      {
         thisUsbFilePath = %A_LoopField%\%usbFile% ; set full path to possible usb file
         IfExist, %thisUsbFilePath% ; if the possible file really exists...
         {
            FileRead, usbKey, %thisUsbFilePath% ; read the usb key
            IfEqual, ErrorLevel, 1, Gosub, DoBlock ; there was an error reading the usb file, block
            lastUsbFilePath := thisUsbFilePath ; remember the correct usb file path
         }
      }
   }
   else ; we already know the usb file path...
   {
      FileRead, usbKey, %lastUsbFilePath% ; read the usb key
      IfEqual, ErrorLevel, 1, Gosub, DoBlock ; there was an error reading the usb file
   }
   ; we should have the keys now, so check the keys
   If (pcKey != "" && usbKey != "" && pcKey = usbKey) ; if the keys are not empty, but equal, unblock
      Gosub, Unblock
   else
      Gosub, Block
Return

DoBlock:
   BlockInput on
   WinKill, Windows Task Manager
   Gui, Show, x0 y0 h%VirtualScreenHeight% w%VirtualScreenWidth% , lock   ;paints over any crack attempt
Return

DoUnblock:
   Gui Destroy
   BlockInput off
   SetTimer, DoCheckKey, off
Return

x: ; "secret" exit keystroke, in case of troubles
DoExit:
   Gosub, DoUnblock
   ExitApp
Return

; disabled keys
Esc::Return


HTH
________________________________________________________
New here? Please, before you post...
1. Read the tutorial and try the examples. -> 2. Take a look at the command list to get an idea of what you could do. -> 3. Create your script. Consult the documentation and the FAQ if you get stuck. -> 4. Search the forum if you need help or examples, method 1 (forum), method 2 (site), method 3 (Google). -> 5. Post your code on the forum in the "Ask for Help" section if you still run into problems (but read this first). -> 6. There is more AHK on autohotkey.net and the Wiki and there is an AHK IRC chat.
Back to top
DeWild1



Joined: 30 Apr 2006
Posts: 358
Location: Shigle Springs

PostPosted: Mon Nov 24, 2008 7:06 pm    Post subject: Reply with quote

add this

Code:
Regwrite, REG_SZ, HKEY_LOCAL_MACHINE,SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\taskmgr.exe, Debugger, Hotkey Disabled
regwrite, REG_DWORD, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System, DisableTaskMgr, 1

Code:
regdelete, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System, DisableTaskMgr
regdelete, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\taskmgr.exe

_________________
CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com
Back to top
View user's profile Send private message Visit poster's website
menaphus



Joined: 28 Nov 2008
Posts: 111
Location: United Kingdom

PostPosted: Fri Nov 28, 2008 11:45 pm    Post subject: Loose your usb drive Reply with quote

I like the idea, having a physical key to unlock it but the thing is what if you actualy lost your usb drive while the pc was locked? Or is it a case of the power button Question

Edit: infact would shuting down the pc with the power button or unplugging it unlock it anyway?
no disrespect just wondering how secure it is/ how long you could leave it
_________________
Adam
http://moourl.com/8w0tx
Back to top
View user's profile Send private message Send e-mail Visit poster's website
fantasybar
Guest





PostPosted: Sun Nov 30, 2008 9:09 am    Post subject: there are some errors Reply with quote

n-l-i-d wrote:
I cleaned up your code a bit (minimized the necessary reads, condensed some code... not tested though), settings in red


there are some errors in your code.
Marked in red


Code:

  #NoTrayIcon

   pcFilePath = C:\WINDOWS\key.txt
   usbFile = key.txt

   OnExit, DoExit

   lastUsbFilePath =
   SysGet, VirtualScreenWidth, 78
   SysGet, VirtualScreenHeight, 79
Return

F8::
   Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
   Gui, Color, 000000
   Gui, Font, x0 y0 cFF0000 s128, Arial
   Gui, Add, Text,
   Gui, Show, x0 y0 h%VirtualScreenHeight% w%VirtualScreenWidth% ,
   SetTimer, DoCheckKey, 200
Return

DoCheckKey:
   ; get pc key
   FileRead, pcKey, %pcFilePath% ; read the pc key
   IfEqual, ErrorLevel, 1, Gosub, DoBlock ; there was an error reading the pc file, block
   ; get usb key
   If not lastUsbFilePath ; if we don't have the usb file path yet...
   {
      DriveGet, allDrives, List, Removable ; get list of removable drives
      Loop, Parse, allDrives ; loop thru all removable drives
      {
         thisUsbFilePath = %A_LoopField%:\%usbFile% ; set full path to possible usb file
         IfExist, %thisUsbFilePath% ; if the possible file really exists...
         {
            FileRead, usbKey, %thisUsbFilePath% ; read the usb key
            IfEqual, ErrorLevel, 1, Gosub, DoBlock ; there was an error reading the usb file, block
            lastUsbFilePath := thisUsbFilePath ; remember the correct usb file path
         }
      }
   }
   else ; we already know the usb file path...
   {
      FileRead, usbKey, %lastUsbFilePath% ; read the usb key
      IfEqual, ErrorLevel, 1, Gosub, DoBlock ; there was an error reading the usb file
   }
   ; we should have the keys now, so check the keys
   If (pcKey != "" && usbKey != "" && pcKey = usbKey) ; if the keys are not empty, but equal, unblock
      Gosub, DoUnblock
   else
      Gosub, DoBlock
Return

DoBlock:
   BlockInput on
   WinKill, Windows Task Manager
   Gui, Show, x0 y0 h%VirtualScreenHeight% w%VirtualScreenWidth% , lock   ;paints over any crack attempt
Return

DoUnblock:
   Gui Destroy
   BlockInput off
   SetTimer, DoCheckKey, off
Return

x: ; "secret" exit keystroke, in case of troubles
DoExit:
   Gosub, DoUnblock
   ExitApp
Return

; disabled keys
Esc::Return
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group