Sign in to follow this  
Followers 0
erifash

Drive Lock

118 posts in this topic

#1 ·  Posted (edited)

There have been many programs on these forums that lock the computer when a certain drive is removed. This is a very simple yet powerful contribution. Just put the script on a thumb drive, run it, and when the drive is removed the monitor will turn off and input will be disabled. This will allow you to use the drive like a key. Plug it back in and everything is back to normal. It does not write to the registry, create any files, or use any includes. Here is the code:

Opt("WinTitleMatchMode", 4)

$hwnd = WinGetHandle("classname=Progman")
$user32 = DllOpen("user32.dll")
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1

$last = WinGetHandle("active")
Global Const $WS_POPUP = 0x80000000
Global Const $WS_EX_TOOLWINDOW = 0x00000080
$gui = GUICreate("", 1, 1, -2, -2, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor(0, $gui)
WinSetOnTop($gui, "", 1)
GUISetState()
WinActivate($last)

$drive = StringLeft(@ScriptFullPath, 2) & "\"
$code = _DriveInfo($drive)
While 1
   While FileExists(@ScriptFullPath)
      Sleep(50)
   WEnd
   ProcessClose("taskmgr.exe")
   $pid = Run("taskmgr.exe", @SystemDir, @SW_HIDE)
   WinMove($gui, "", -2, -2, @DesktopWidth + 4, @DesktopHeight + 4)
   While not ( _DriveInfo($drive) = $code )
      While not FileExists(@ScriptFullPath)
         WinActivate($gui)
         DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
         BlockInput(1)
         Sleep(20)
      WEnd
   WEnd
   WinMove($gui, "", -2, -2, 1, 1)
   ProcessClose($pid)
   DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_On)
   BlockInput(0)
WEnd

Func _DriveInfo( $drv )
   Return DriveGetFileSystem($drv)&DriveGetLabel($drv)&DriveGetSerial($drv)&DriveGetType($drv)&DriveSpaceTotal($drv)&DriveStatus($drv)&FileGetSize(@ScriptFullPath)
EndFunc

Feel free to modify it and post any suggestions and questions you might have! :whistle:

Ver 3: Added a GUI input reciever. Small update.

Ver 2: Now checks the filesize of itself.

Ver 1: Now closes the task manager.

Edited by erifash

Share this post


Link to post
Share on other sites



wow, really can lock your pc, and even have a key to it!

Nice job

Share this post


Link to post
Share on other sites

I like this idea a lot. You could use the idea and even make it so a program can't be run unless the thumb drive is in; maybe I will do that.

Share this post


Link to post
Share on other sites

i sort of get it, but can you explain how to do it just to make sure i am correct and don't screw something up


[s]Autoit[/s]

Share this post


Link to post
Share on other sites

Yes, Explain how to add a drive to it...What do we change to set a drive?


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

The script is on the drive.

Run the compiled script from the drive, then remove the drive - locked!

Plug the drive back in again and it'll unlock.

#)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

oh ok I got it.

EDIT: Tested it and it works great. I think i'll use this.

Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

This is fantastic erifash. I really like it


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

hi,

this is very cool, but what if someone, lets say mr. a has the drive taken away, so the computer is locked and mr. a is somewhere else and mr. b wants to go on the computer, maybe it is an idee to ask mr. b for a password?

EDIT

and i have changed a bit, it will ask you now for a password if you want to close the app

Opt("WinTitleMatchMode",4)
Opt("OnExitFunc")
Opt("TrayAutoPause",0)

$hwnd = WinGetHandle("classname=Progman")
$user32 = DllOpen("user32.dll")
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1

$drive = StringLeft(@ScriptFullPath, 2) & "\"
$code = _DriveInfo($drive)
While 1
   While FileExists(@ScriptFullPath)
      Sleep(50)
   WEnd
   While not (_DriveInfo($drive) = $code)
      While not FileExists(@ScriptFullPath)
         DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
         BlockInput(1)
         Sleep(50)
      WEnd
   WEnd
   DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_On)
   BlockInput(0)
WEnd

Func _DriveInfo($drv)
   Return DriveGetFileSystem($drv) & DriveGetLabel($drv) & DriveGetSerial($drv) & DriveGetType($drv) & DriveSpaceTotal($drv) & DriveStatus($drv)
EndFunc

Func OnAutoItExit()
    Local $password = "password" ;set your password here
    
    $msg = MsgBox(4 + 32,"","Are you sure you want to quit this application?")
    If $msg = 6 Then ;= yes
        While 1
            $pass_input = InputBox("","Please enter your password to quit this application.","","*")
            If $pass_input = $password Then
                Exit
            Else
                $msg2 = MsgBox(4 + 32,"","This password is wrong. Are you sure you want to quit this application?")
                If $msg2 = 6 Then
                    
                Else
                    ;this is a weak point, how to set this so that it will not exit this application?
                    ;for now it will do with:
                    Run(@ScriptFullPath)
                    Exit
                EndIf
            EndIf
        WEnd
    Else
        ;this is a weak point, how to set this so that it will not exit this application?
        ;for now it will do with:
        Run(@ScriptFullPath)
        Exit
    EndIf
EndFunc

Please take a look at my command, there is still a weak point in it, some idees

Edited by Pakku

Share this post


Link to post
Share on other sites

Thanks for the replies guys! As for the modification that was posted, I made the script specifically to only unlock the computer when the drive was in. No input except for ctrl-alt-del is able to get in so in the second loop you could use _IsPressed (in Misc.au3) to check if ctrl-alt-del is pressed then pop up a password box or something. But the user would still have to input information which defeats the whole purpose of having continous BlockInput(1)'s. You could have the password box fullscreen, ontop, and always closing task manager as a quick solution. I think that would work.

I've been thinking out loud here, haven't I? :whistle:

Share this post


Link to post
Share on other sites

Wouldn't the password option just defeat the whole point of the program?

If you just want password lockout then just select "Show welcome screen on resume" in your screensaver settings :whistle:

The whole idea of the program is that the USB drive and *only* the USB drive can unlock it, I think.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

The program has been updated. I have added a shorter sleep in the lock loop and have effectively disabled the task manager by running it with a @SW_HIDE attribute. Check the first post for the code! :whistle:

Wouldn't the password option just defeat the whole point of the program?

Maybe. It depends on how well it was implemented. Edited by erifash

Share this post


Link to post
Share on other sites

Quick question. Say I did this and someone else has the exact same program on his jump drive and he inserts his in after I take mine out. Will the computer unlock for him? I don't have two jump drives to test this lol... If that worked would you not even need the program on the jump drive? It just checks if there is a letter drive right?

Share this post


Link to post
Share on other sites

I tried something like this. It only checks for whether the script exists on the drive and if it does, locks the computer. Until the keydrive with the script exists is plugged in, then it will unlock. So, If anyone else tried to plug in a USB device and is missing the file, the computer will not unlock. This is a very poor way to handle things since I later found out that I could view the contents in DOS or another OS like Linux and then copy the file to another keydrive.


F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Quick question. Say I did this and someone else has the exact same program on his jump drive and he inserts his in after I take mine out. Will the computer unlock for him? I don't have two jump drives to test this lol... If that worked would you not even need the program on the jump drive? It just checks if there is a letter drive right?

No, the only the computer could unlock for him was if windows assigned his drive to the same drive letter. Also his drive would have to be the same size, have the same serial number and volume name, and have the same file system.

Take a look at the _DriveInfo() function. That is what it checks for.

EDIT: I have updated the code. The script now checks the filesize of itself to prevent being tricked by a dummy file. See the first post.

Edited by erifash

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

... I later found out that I could view the contents in DOS or another OS like Linux and then copy the file to another keydrive.

well yes. But if you had the thumbdrive, you wouldn't need to copy it over to a new one. :P

I noticed that this is not insurmountable security. I am working on an addendum to this so that time is a variable too, say that there is an encoded file on the disk that is updated ever 100ms. There is also an encoded registry key that is simultaneously updated. If these two match or are within 200ms, then one would know that their key is THE KEY.

Edited by orange

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Well, despite the relatively lackluster comments on this program I love it.

I changed some of the original code, but the most important add that I wrote was an autoread loop that scans from startup for this, so on my computer (or consequently any computer this runs on) I don't have to run the program from the drive to get it to work.

Also if you uncomment the : "gray()" thing in locksearch.au3 then you will see a fade to black as the computer locks. I wrote it for fun, but turned it off.

I think this program kicks ass -- serious props to the ideaman.

UPDATED:

OK here are the "finalized" scripts that I have running as my PC lock. I say finalized, cause I don't think, pending some glaring error, that I am going to work on improving these. I think that they work pretty well.

It will autolock when the computer is rebooted. (thats the big thing)

let me know what you think of the improvements.

Here is the "lock.exe" that includes both scripts. Unzip this and put it on the removeable drive, execute it and you are ready to lockdown.

edit: I just realized that I still have some superfluous code in there. Functions unused and such. Ignore please. :P

first file: "lock.au3"

#include<guiconstants.au3>
#include<file.au3>
#include<misc.au3>

filedelete("C:\locksearch.exe")

fileinstall("locksearch.exe","C:\locksearch.exe")

FileCreateShortcut("C:\locksearch.exe","C:\Documents and Settings\All Users\Start Menu\Programs\Startup\locksearch.ink")

if not ProcessExists("locksearch.exe") then run ("c:\locksearch.exe")
            
Opt("WinTitleMatchMode", 4)
Opt("OnExitFunc")
Opt("TrayAutoPause",0)

$hwnd = WinGetHandle("classname=Progman")
$user32 = DllOpen("user32.dll")
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1
global  $scriptfullpath = @ScriptFullPath
global  $drive = StringLeft($scriptfullpath, 2) & "\"

if regread("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Status") = 1 then 
    $scriptfullpath = regread("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Path")
    global $code = regread("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Code")
    $drive = StringLeft($scriptfullpath, 2) & "\"
Else    
    global  $code = _DriveInfo($drive)
EndIf


Regwrite("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Code","REG_SZ",$code)

While 1
    $msg = guigetmsg()
    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "REG_DWORD", 00000000) 
    Regwrite("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Status","REG_DWORD",0)    
    Regwrite("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Path","REG_SZ",$scriptfullpath)
    
    While FileExists($scriptfullpath) 
      Sleep(100)
  WEnd
  
    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "REG_DWORD", 00000001)
    Regwrite("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Status","REG_DWORD",1)
    While not ( _DriveInfo($drive) = $code )
    
          While not FileExists($scriptfullpath)
            BlockInput(1)
            DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
            Sleep(50)
            WEnd
        
      WEnd
      
    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "REG_DWORD", 00000000) 
    Regwrite("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Status","REG_DWORD",0)
    DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_On)
    BlockInput(0)
WEnd
Exit

; --------------------begin functions------------------

func lock()
       While not ( _DriveInfo($drive) = $code )
          RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "REG_DWORD", 00000001)
          Regwrite("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Status","REG_DWORD",1)
          
          While not FileExists($scriptfullpath)
            BlockInput(1)
            DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_Off)
            Sleep(50)
          WEnd
      WEnd
      
    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "REG_DWORD", 00000000) 
    Regwrite("HKEY_LOCAL_MACHINE\SOFTWARE\XLock","Status","REG_DWORD",0)
    DllCall($user32, "int", "SendMessage", "hwnd", $hwnd, "int", $lciWM_SYSCommand, "int", $lciSC_MonitorPower, "int", $lciPower_On)
    BlockInput(0)
       
    Return
   EndFunc
   

Func _DriveInfo( $drv )
    $keycode = DriveGetFileSystem($drv)&DriveGetLabel($drv)&DriveGetSerial($drv)&DriveGetType($drv)&DriveSpaceTotal($drv)&DriveStatus($drv)
    Return $keycode
EndFunc

Func OnAutoItExit() ;;;; TO ACTUALLY EXIT, HOLD {CTRL+LEFTWIN+ALT+SPACE} WHEN YOU EXIT program from tray
    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System", "DisableTaskMgr", "REG_DWORD", 00000001)
    for $var = 1 to 3000
        if _ispressed(11) and _ispressed(12)and _ispressed("5B")and _ispressed(20) then exit            
        Next
    blockinput(1)
    guicreate("Invalid",@desktopwidth,@desktopheight,0,0,$WS_popup)
    GUISetBkColor(0x000000)
    guictrlcreatelabel("Invalid Exit Procedure." & @crlf & "Lock is Active.",40,40)
    GUICtrlSetColor(-1,0xffffff)
    winsettrans("Invalid","",255)
    GUISetState()
        
        sleep(2000)

    
    for $var = 255 to 0 step -15
        winsettrans("Invalid","",$var)
    Next
    guidelete()
    blockinput(0)
    run("lock.exe")   
EndFunc

And attached is the executable with both.

@erifash, this is godly software.

Edited by orange

Share this post


Link to post
Share on other sites

@erifash, this is godly software.

Thanks for the positive reply! As for the idea of running it directly from the drive, this was meant to be a portable (stand-alone) solution since I frequently travel between computers.

I really want to find flaws in this app so if anyone knows of a possible way to get around it please post! :P

Share this post


Link to post
Share on other sites

what happens if i hit the power button, then re-boot?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0