SpookMeister Posted December 20, 2005 Posted December 20, 2005 (edited) I have a few co-workers that love messing with my system whenever I leave it unlocked. I got tired of it, and couldn't seam to make myself change the habbit of walking away without locking when something comes up, so I made this program to help me out. Hope you like it. -Spook P.S. Requires Beta expandcollapse popup#Include <Misc.au3> #Include <Constants.au3> #Include <GUIConstants.au3> #NoTrayIcon $g_szVersion = "LockWork v1.4" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) $reg = RegRead("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "LastUsed") If @error Then RegWrite("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "LastUsed", "REG_SZ", @YEAR & @MON & @MDAY) RegWrite("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "IdleTime", "REG_SZ", 2) RegWrite("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "HotKeyEnabled", "REG_SZ", 1) Else RegWrite("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "LastUsed", "REG_SZ", @YEAR & @MON & @MDAY) EndIf opt("TrayMenuMode", 1) $settingsitem = TrayCreateItem ("Settings") TrayCreateItem ("") $aboutitem = TrayCreateItem ("About") TrayCreateItem ("") $exititem = TrayCreateItem ("Exit") TraySetState () TraySetIcon ("Shell32.dll", 104) TraySetToolTip ("LockWork - a utility for auto-locking your system") Dim $s_keys[117] = [116, _ "01", "02", "04", "05", "06", "08", "09", "0C", "0D", "10", _ "11", "12", "13", "14", "1B", "20", "21", "22", "23", "24", _ "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", _ "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", _ "41", "42", "44", "45", "46", "47", "48", "49", "4A", "4B", _ "4C", "4D", "4E", "4F", "50", "51", "52", "53", "54", "55", _ "56", "57", "58", "59", "5A", "5B", "5C", "60", "61", "62", _ "63", "64", "65", "66", "67", "68", "69", "6A", "6B", "6C", _ "6D", "6E", "6F", "70", "71", "72", "73", "74", "75", "76", _ "77", "78", "79", "7A", "7B", "7C", "7D", "7E", "7F", "80H", _ "81H", "82H", "83H", "84H", "85H", "86H", "87H", "90", "91", _ "A0", "A1", "A2", "A3", "A4", "A5"] $dll = DllOpen("user32.dll") Dim $oldpos[2] Dim $pos[2] $min = RegRead("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "IdleTime") If @error Then $min = 2 $hot = RegRead("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "HotKeyEnabled") If $hot <> 4 Then HotKeySet("{F8}", "LockIt") $warn = 1 $time = ($min * 60) * 1000 $pos = MouseGetPos() $start = TimerInit() While 1 ; Check for menu interaction $msg = TrayGetMsg () Select Case $msg = $aboutitem MsgBox(64, "about:", "This is a program that auto-locks the computer " _ & "if idle for a period of time") Case $msg = $exititem Exit Case $msg = $settingsitem SettingsGUI() EndSelect Sleep (100) ; See if any keys have been pressed For $y = 1 To $s_keys[0] If _IsPressed ($s_keys[$y], $dll) Then $start = TimerInit() EndIf Next ; See if the mouse has moved $oldpos[0] = $pos[0] $oldpos[1] = $pos[1] $pos = MouseGetPos() If Not $oldpos[1] = $pos[1] Or Not $oldpos[0] = $pos[0] Then $start = TimerInit() EndIf ; If system has stayed idle too long kick off the lock function If TimerDiff($start) > $time Then WarnLockIt() ; If the system is locked then reset the timer checkLock() WEnd Func checkLock() $locked=DllCall("user32","Long","OpenInputDesktop") ;LogLine(@HOUR & @MIN & @SEC & " dll call = " & $locked[0]) If $locked[0] = 0 Then $start = TimerInit() EndFunc Func LogLine($line) $log = FileOpen("C:\lockworklog.txt",1) FileWriteLine($log,$line) FileClose($log) EndFunc Func WarnLockIt() If $warn = 1 then $ok = MsgBox(4096, "Idle Warning", "You system will lock in a few seconds unless you press OK",10) If $ok = 1 then $start = TimerInit() Return EndIf EndIf LockIt() EndFunc ;==>LockIt Func LockIt() Run("rundll32.exe user32.dll,LockWorkStation") $start = TimerInit() EndFunc ;==>LockIt Func SettingsGUI() $title = "LockWork Settings" GUICreate($title, 200, 150, -1, -1, $WS_SIZEBOX) GUICtrlCreateLabel("Minutes to wait untill lock:", 10, 15) $input = GUICtrlCreateInput(RegRead("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", _ "IdleTime"), 140, 10, 40, 20) $updown = GUICtrlCreateUpdown($input) GUICtrlSetLimit($updown,99,1) GUICtrlCreateLabel("Enable HotKey {F8}: ", 20, 50) $hotkey = GUICtrlCreateCheckbox("", 140, 50, 20, 20) $hotval = RegRead("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "HotKeyEnabled") If $hotval = 4 Then GUICtrlSetState($hotkey, $GUI_UNCHECKED) Else GUICtrlSetState($hotkey, $GUI_CHECKED) EndIf $btn = GUICtrlCreateButton("OK", 50, 90, 80) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $btn ExitLoop EndSelect WEnd $hotval = GUICtrlRead($hotkey) RegWrite("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "HotKeyEnabled", "REG_SZ", $hotval) If $hotval = 4 Then HotKeySet("{F8}") Else HotKeySet("{F8}", "LockIt") EndIf RegWrite("HKEY_CURRENT_USER\SOFTWARE\LockWork\Settings", "IdleTime", "REG_SZ", GUICtrlRead($input)) $time = (GUICtrlRead($input) * 60) * 1000 GUIDelete() EndFunc ;==>SettingsGUI Edit: tweaked a few things [edit2] used the autoit code box Edited December 17, 2007 by SpookMeister [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]
Gigglestick Posted December 20, 2005 Posted December 20, 2005 (edited) Why not just set the screen saver to lock the computer and to time out after 1 or 2 minutes? If you're using XP, Windows+L will lock it. I understand the habit of walking away, but when the effort is reduced to Win+L, well.... Edited December 20, 2005 by c0deWorm My UDFs: ExitCodes
SpookMeister Posted December 20, 2005 Author Posted December 20, 2005 Not using XP, and corporate policy forbids screen savers... not to mention the "cause I can" factor. [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]
Gigglestick Posted December 21, 2005 Posted December 21, 2005 (edited) *EDIT* Nevermind. Edited December 21, 2005 by c0deWorm My UDFs: ExitCodes
SpookMeister Posted April 3, 2006 Author Posted April 3, 2006 :Added a function to detect if the workstation was locked [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]
dandymcgee Posted July 29, 2006 Posted July 29, 2006 I think that's a great program, nice idea and i love it!!! - Dan [Website]
Impulse08 Posted August 2, 2006 Posted August 2, 2006 An easy workstation lock is to just have scheduled task to run when idle. For instance I have my scheduled task run when the computer is idle for 5 minutes, then it runs a bat file which contains: @echo off rundll32.exe user32.dll, LockWorkStation cls works for WinXP and I think a few other Windows OS. -- If the apocalypse comes... beep me.
busysignal Posted August 13, 2006 Posted August 13, 2006 Not using XP, and corporate policy forbids screen savers... not to mention the "cause I can" factor.@SpookMeister, Great response. You can find a lot of programs that "CAN" do the job outside of writing it in AutoIt. But the "Cause I Can" should always come to mind for people - at least for me it should. But other scripters should take code that they like and implement it into their own code to enhance AutoIt.Cheers..
comart Posted August 20, 2006 Posted August 20, 2006 Good code ! btw, I have another approaching. AutoMee (my utility) allows user to set Idle time and after that time, a message appears like: Inactive for xx seconds, locking down... (this dialog auto disappears in 10s) Move mouse to skip locking and double next idle time. If you are watching a movie and auto-lock feature comes up, just touch your mouse and keep watching movie for a longer time Download the program and try yourself this feature. Do you think this ok ? >> AutoMee << NICE AutoIt UTILITY THAT I CAN'T LIVE WITHOUT !
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now