CWorks Posted August 6, 2006 Share Posted August 6, 2006 (edited) basically i hacked this together and am pretty sure it's very screwed upso if some AutoIt guru could take a look at it and tell me if i'm way off or notit does work as intended though just was unable to add tray menu functions, with them it no longer works so i commented them outdidn't realy know where to put them eitherit also seems to eat a lot of mem when running (4 megs) probably my hacking and don't anyone tell me to read the help because i'm always reading it every step of the way or else i wouldn't have gotten this far there's nothing better than working examplesoh i guess i should say what this iswell it's a screen lock program for BartPE based on one from Hallman and posted hereit's no longer made to work in windows only in BartPECODE;AutoIt Version : 3.1.1.132;my feable attempt at a screen lock program for BartPE#NoTrayIconHotKeySet("{F11}", "Lock")Global $Go_Button = -999Dim $Atempts = 0Dim $Lock = 0Dim $PassInput = ""Dim $Label#include <guiconstants.au3>#include <string.au3>Dim $ScreenyWindow = ""$bart = RegRead('HKLM\System\CurrentControlSet\Control\Pe Builder', 'Name')If @error = 1 Then $NewPass = InputBox("Create Password", "Enter your password", "", "*", 100, 100) If @error = 1 Then Exit $PassWord = $NewPass FileDelete("test.txt") $file = FileOpen("test.txt", 1) $crap = _StringEncrypt(1, $PassWord, "4471") Sleep(1200) FileWrite($file, "[Version]" & @CRLF) $Software_AddReg = 'Signature= "$Windows NT$"' FileWrite($file, $Software_AddReg & @CRLF & @CRLF) FileWrite($file, "[PEBuilder]" & @CRLF) $Software_AddReg = 'Name="Screen Lock"' FileWrite($file, $Software_AddReg & @CRLF) FileWrite($file, "Enable=1" & @CRLF & @CRLF) FileWrite($file, "[sourceDisksFiles]" & @CRLF) FileWrite($file, "ScreenLock.exe=2,,1" & @CRLF & @CRLF) FileWrite($file, "[software.AddReg]" & @CRLF) $Software_AddReg = '0x1,"ScreenLock","Password","' FileWrite($file, $Software_AddReg & $crap & Chr(34) & @CRLF) $Software_AddReg = '0x2,"Sherpya\XPEinit\Desktop","ScreenLock","%SystemRoot%\system32\ScreenLock.exe"' FileWrite($file, $Software_AddReg & @CRLF) FileClose($file) ExitEndIfLock()#comments-startTrayCreateItem("")$lockitem = TrayCreateItem("Lock")TrayCreateItem("")$aboutitem = TrayCreateItem("About")TrayCreateItem("")$exititem = TrayCreateItem("Exit")TraySetState()While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $lockitem Lock() Case $msg = $aboutitem Msgbox(64,"about:","ScreenLock pre alpha") Case $msg = $exititem ExitLoop EndSelectWEndExit#comments-end$PassWord = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\ScreenLock", "Password")If $PassWord <> "" Then $PassWord = _StringEncrypt(0, $PassWord, "4471")EndIf$Show_Controls_Timer = TimerInit()$Controls_Shown = 0While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE And $Lock = 0 Exit Case $msg = $Go_Button If GUICtrlRead($PassInput) == $PassWord Then Lock() MsgBox(0,"Atempts","An incorrect password was entered " & $Atempts & " time(s).") $Atempts = 0 Else $Atempts += 1 SplashMsg("Error","Invalid Password",220,100) EndIf Case $msg = $GUI_EVENT_PRIMARYUP And $Lock = 1 GUISetState(@SW_SHOW,$PassWindow) $Controls_Shown = 1 $Show_Controls_Timer = TimerInit() EndSelect If TimerDiff($Show_Controls_Timer) > 10000 And $Controls_Shown = 1 Then GUISetState(@SW_HIDE,$PassWindow) $Controls_Shown = 0 EndIf If WinExists("Windows Task Manager") And $Lock = 1 Then WinClose("Windows Task Manager") WinKill("Windows Task Manager") EndIf If WinActive($ScreenyWindow) = 0 And WinActive($PassWindow) = 0 And $Lock = 1 Then WinActivate($ScreenyWindow) EndIf If Not BitAnd(WinGetState($ScreenyWindow, ""),2) = 1 And $Lock = 1 Then GUISetState (@SW_SHOW) EndIf If $Lock = 1 And WinExists($ScreenyWindow) = 0 Then $ScreenyWindow = GUICreate("",@DesktopWidth,@DesktopHeight,-2,-2,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($ScreenyWindow) WinSetTrans($ScreenyWindow,"",1) Global $PassWindow = GUICreate("",220,90,-1,-1,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($PassWindow) GUISetState(@SW_HIDE) Global $Label = GUICtrlCreateLabel("The screen has been locked.",10,10,-1,15) GUICtrlSetColor(-1,0xff0000) Global $PassInput = GUICtrlCreateInput("Password",10,30,200,20,$ES_PASSWORD) Global $Go_Button = GUICtrlCreateButton("Unlock",60,60,100,20) GUISetState(@SW_SHOW,$ScreenyWindow) WinSetOnTop($ScreenyWindow, "", 1) WinSetOnTop($PassWindow, "", 1) EndIf WEndFunc Lock() If $Lock = 0 Then $ScreenyWindow = GUICreate("",@DesktopWidth + 2,@DesktopHeight + 2,-2,-2,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($ScreenyWindow) WinSetTrans($ScreenyWindow,"",1) Global $PassWindow = GUICreate("",220,90,-1,-1,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($PassWindow) GUISetState(@SW_HIDE) Global $Label = GUICtrlCreateLabel("The screen has been locked.",10,10,-1,15) GUICtrlSetColor(-1,0xff0000) Global $PassInput = GUICtrlCreateInput("Password",10,30,200,20,$ES_PASSWORD) Global $Go_Button = GUICtrlCreateButton("Unlock",60,60,100,20) GUISetState(@SW_SHOW,$ScreenyWindow) WinSetOnTop($ScreenyWindow, "", 1) WinSetOnTop($PassWindow, "", 1) $Lock = 1 Else GUIDelete($ScreenyWindow) GUIDelete($PassWindow) $Lock = 0 EndIf EndFuncFunc SplashMsg($S_Title = "",$S_Text = "",$S_Size_X = 300,$S_Size_Y = 300) SplashTextOn($S_Title,$S_Text & @CRLF & "Press Enter to close this window.",$S_Size_X,$S_Size_Y) HotKeySet("{ENTER}","OffSplash")EndFuncFunc OffSplash() SplashOff() HotKeySet("{ENTER}") EndFuncforgot how to spell Edited August 6, 2006 by CWorks Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 6, 2006 Moderators Share Posted August 6, 2006 (edited) For your CPU usage, try Sleep(10) in your While 1 loop. I started to look at the rest of your code, but it looks like you took something out (Like the original GUI?)... Edit: Nevermind, I found them. I would suggest to build the GUI First, and just hide it, then use GUISetState(@SW_SHOW) when you want to use it. You have an If statement and a Lock() function that both build the same GUI (any reason for that?)... Again, the code is really hard to follow, sorry not to be more help there, but my eyes are a bit criss crossed this morning. Edited August 6, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
CWorks Posted August 6, 2006 Author Share Posted August 6, 2006 (edited) well i said it was hack job I did renove the gui because i don't need it and this is as far as i could get it without breaking it the way it was originally there was a box that popped up to enter a new password which would then get added to reg and then you could lock it the way i want it is if started in xp it pops up a box for password and then spits out an .inf file which is a plugin file for pebuilder in pe it just starts up locked instead of the way it was and it was hiding the box until you unlocked it and it's not really what i wanted but i would get errors if i removed just that part so i stripped it all out and it worked which amazed me original lock function before i removed some parts i tried to comment out the 2 at the bottom but it would give errors i think i'm over my head with all the loops and if then while loops maybe i'll start over again Func Lock() If $Lock = 0 Then GUISwitch($MainWindow) GUISetState(@SW_HIDE,$MainWindow) $ScreenyWindow = GUICreate("",@DesktopWidth + 2,@DesktopHeight + 2,-2,-2,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($ScreenyWindow) WinSetTrans($ScreenyWindow,"",1) Global $PassWindow = GUICreate("",220,90,-1,-1,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($PassWindow) GUISetState(@SW_HIDE) Global $Label = GUICtrlCreateLabel("The screen has been locked.",10,10,-1,15) GUICtrlSetColor(-1,0xff0000) Global $PassInput = GUICtrlCreateInput("Password",10,30,200,20,$ES_PASSWORD) Global $Go_Button = GUICtrlCreateButton("Unlock",60,60,100,20) GUISetState(@SW_SHOW,$ScreenyWindow) WinSetOnTop($ScreenyWindow, "", 1) WinSetOnTop($PassWindow, "", 1) $Lock = 1 Else GUIDelete($ScreenyWindow) GUIDelete($PassWindow) ; GUISwitch($MainWindow) ; GUISetState(@SW_SHOW,$MainWindow) $Lock = 0 EndIf ok i took out the non essential bits so it works in normal windows with password set to doggy and this is exactly what i want it to do just don't know what to change in the loops well i understand it until it comes time to remove parts that i don't wan't not sure what if anything to put in it's place CODE;#NoTrayIcon HotKeySet("{F11}", "Lock") Global $Go_Button = -999 Dim $Atempts = 0 Dim $Lock = 0 Dim $PassInput = "" Dim $Label #include <guiconstants.au3> #include <string.au3> Dim $ScreenyWindow = "" Lock() $PassWord = "doggy" $Show_Controls_Timer = TimerInit() $Controls_Shown = 0 While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE And $Lock = 0 Exit Case $msg = $Go_Button If GUICtrlRead($PassInput) == $PassWord Then Lock() MsgBox(0,"Atempts","An incorrect password was entered " & $Atempts & " time(s).") $Atempts = 0 Else $Atempts += 1 SplashMsg("Error","Invalid Password",220,100) EndIf Case $msg = $GUI_EVENT_PRIMARYUP And $Lock = 1 GUISetState(@SW_SHOW,$PassWindow) $Controls_Shown = 1 $Show_Controls_Timer = TimerInit() EndSelect If TimerDiff($Show_Controls_Timer) > 10000 And $Controls_Shown = 1 Then GUISetState(@SW_HIDE,$PassWindow) $Controls_Shown = 0 EndIf If WinExists("Windows Task Manager") And $Lock = 1 Then WinClose("Windows Task Manager") WinKill("Windows Task Manager") EndIf If WinActive($ScreenyWindow) = 0 And WinActive($PassWindow) = 0 And $Lock = 1 Then WinActivate($ScreenyWindow) EndIf If Not BitAnd(WinGetState($ScreenyWindow, ""),2) = 1 And $Lock = 1 Then GUISetState (@SW_SHOW) EndIf If $Lock = 1 And WinExists($ScreenyWindow) = 0 Then $ScreenyWindow = GUICreate("",@DesktopWidth,@DesktopHeight,-2,-2,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($ScreenyWindow) WinSetTrans($ScreenyWindow,"",1) Global $PassWindow = GUICreate("",220,90,-1,-1,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($PassWindow) GUISetState(@SW_HIDE) Global $Label = GUICtrlCreateLabel("The screen has been locked.",10,10,-1,15) GUICtrlSetColor(-1,0xff0000) Global $PassInput = GUICtrlCreateInput("Password",10,30,200,20,$ES_PASSWORD) Global $Go_Button = GUICtrlCreateButton("Unlock",60,60,100,20) GUISetState(@SW_SHOW,$ScreenyWindow) WinSetOnTop($ScreenyWindow, "", 1) WinSetOnTop($PassWindow, "", 1) EndIf WEnd Func Lock() If $Lock = 0 Then $ScreenyWindow = GUICreate("",@DesktopWidth + 2,@DesktopHeight + 2,-2,-2,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($ScreenyWindow) WinSetTrans($ScreenyWindow,"",1) Global $PassWindow = GUICreate("",220,90,-1,-1,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($PassWindow) GUISetState(@SW_HIDE) Global $Label = GUICtrlCreateLabel("The screen has been locked.",10,10,-1,15) GUICtrlSetColor(-1,0xff0000) Global $PassInput = GUICtrlCreateInput("Password",10,30,200,20,$ES_PASSWORD) Global $Go_Button = GUICtrlCreateButton("Unlock",60,60,100,20) GUISetState(@SW_SHOW,$ScreenyWindow) WinSetOnTop($ScreenyWindow, "", 1) WinSetOnTop($PassWindow, "", 1) $Lock = 1 Else GUIDelete($ScreenyWindow) GUIDelete($PassWindow) $Lock = 0 EndIf EndFunc Func SplashMsg($S_Title = "",$S_Text = "",$S_Size_X = 300,$S_Size_Y = 300) SplashTextOn($S_Title,$S_Text & @CRLF & "Press Enter to close this window.",$S_Size_X,$S_Size_Y) HotKeySet("{ENTER}","OffSplash") EndFunc Func OffSplash() SplashOff() HotKeySet("{ENTER}") EndFunc Edited August 6, 2006 by CWorks Link to comment Share on other sites More sharing options...
CWorks Posted August 6, 2006 Author Share Posted August 6, 2006 ok i started over and this time no errors after commenting out the 2 $MainWindow at the end so now how to stop box from popping up at the start and just lock it from the start ah i got it putting Lock() in the right place takes care of it all i did this time to original was add Lock() before While 1 and comment the 2 $MainWindow at the end I guess i got a little carried away last time Link to comment Share on other sites More sharing options...
CWorks Posted August 6, 2006 Author Share Posted August 6, 2006 (edited) Never mind i figured it all out myselfjust had to think about it before ripping it all apart this timeI tend to answer my own questions all the time this is where i need some helpI want to remove all the commented stuff but i don't know how to connect the dots afterwardsI just kept taking endif's or adding until autoit stopped bitchingi've already removed any parts from above dealing wit this and it worksby just commenting out Case $msg = $SetPassButtoni just want to lighten the file a little of stuff no longer used and just wasting spaceexpandcollapse popupWhile 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE And $Lock = 0 Exit Case $msg = $LockButton Lock() #comments-start Case $msg = $SetPassButton If $PassWord <> "" Then $OldPass = InputBox("Old Password","Enter your old password","","*") If $OldPass == $PassWord Then $NewPass = InputBox("New Password","Enter your new password") If @error Then EndIf ElseIf @error Then Else MsgBox(16,"error","Invalid password.") EndIf Else $NewPass = InputBox("New Password","Enter your new password") If @error Then Else $PassWord = $NewPass RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Andy\ScreenLock", "Password","REG_SZ", _StringEncrypt(1,$PassWord,"4471")) GUISwitch($MainWindow) GUICtrlSetState($LockButton,$GUI_ENABLE) #comments-end EndIf EndIf Case $msg = $Go_Button If GUICtrlRead($PassInput) == $PassWord Then Lock() MsgBox(0,"Atempts","An incorrect password was entered " & $Atempts & " time(s).") $Atempts = 0 Else $Atempts += 1 SplashMsg("Error","Invalid Password",220,100) EndIf Case $msg = $GUI_EVENT_PRIMARYUP And $Lock = 1 GUISetState(@SW_SHOW,$PassWindow) $Controls_Shown = 1 $Show_Controls_Timer = TimerInit() EndSelect If TimerDiff($Show_Controls_Timer) > 10000 And $Controls_Shown = 1 Then GUISetState(@SW_HIDE,$PassWindow) $Controls_Shown = 0 EndIf If WinExists("Windows Task Manager") And $Lock = 1 Then WinClose("Windows Task Manager") WinKill("Windows Task Manager") EndIf If WinActive($ScreenyWindow) = 0 And WinActive($PassWindow) = 0 And $Lock = 1 Then WinActivate($ScreenyWindow) EndIf If Not BitAnd(WinGetState($ScreenyWindow, ""),2) = 1 And $Lock = 1 Then GUISetState (@SW_SHOW) EndIf If $Lock = 1 And WinExists($ScreenyWindow) = 0 Then GUISwitch($MainWindow) GUISetState(@SW_HIDE,$MainWindow) $ScreenyWindow = GUICreate("",@DesktopWidth,@DesktopHeight,-2,-2,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($ScreenyWindow) WinSetTrans($ScreenyWindow,"",1) Global $PassWindow = GUICreate("",220,90,-1,-1,$WS_POPUPWINDOW,$WS_EX_TOOLWINDOW) GUISwitch($PassWindow) GUISetState(@SW_HIDE) Global $Label = GUICtrlCreateLabel("The screen has been locked.",10,10,-1,15) GUICtrlSetColor(-1,0xff0000) Global $PassInput = GUICtrlCreateInput("Password",10,30,200,20,$ES_PASSWORD) Global $Go_Button = GUICtrlCreateButton("Unlock",60,60,100,20) GUISetState(@SW_SHOW,$ScreenyWindow) WinSetOnTop($ScreenyWindow, "", 1) WinSetOnTop($PassWindow, "", 1) EndIf WEnd Edited August 6, 2006 by CWorks Link to comment Share on other sites More sharing options...
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