Jump to content

Would like a little help and advice


Recommended Posts

basically i hacked this together and am pretty sure it's very screwed up

so if some AutoIt guru could take a look at it and tell me if i'm way off or not

it does work as intended though just was unable to add tray menu functions, with them it no longer works so i commented them out

didn't realy know where to put them either

it 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 examples

oh i guess i should say what this is

well it's a screen lock program for BartPE based on one from Hallman and posted here

it's no longer made to work in windows only in BartPE

CODE

;AutoIt Version : 3.1.1.132

;my feable attempt at a screen lock program for BartPE

#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 = ""

$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)

Exit

EndIf

Lock()

#comments-start

TrayCreateItem("")

$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

EndSelect

WEnd

Exit

#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 = 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

forgot how to spell :whistle:

Edited by CWorks
Link to comment
Share on other sites

  • Moderators

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 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

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 :whistle:

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 by CWorks
Link to comment
Share on other sites

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

Never mind i figured it all out myself

just had to think about it before ripping it all apart this time

I tend to answer my own questions all the time :whistle:

this is where i need some help

I want to remove all the commented stuff but i don't know how to connect the dots afterwards

I just kept taking endif's or adding until autoit stopped bitching

i've already removed any parts from above dealing wit this and it works

by just commenting out Case $msg = $SetPassButton

i just want to lighten the file a little of stuff no longer used and just wasting space

While 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 by CWorks
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...