Sign in to follow this  
Followers 0
Thudo

Enhancing AutoIT ScreenSaver Example

7 posts in this topic

#1 ·  Posted (edited)

Thanks to the AutoIT community..

Essentially what I need coded/integrated into that is as follows:

1) Based on a setting in the screensaver.cfg, to determine inactivity to then enable the picture screensaver.

2) Enable the screensaver using a HOTKEY combo (our WINDOWS keys are non-functional so we need other key combos)

3) Password protect the screensaver so when it comes out of the picture slideshow it asks for a password (this password is stored in screensaver.cfg and locally in registry *in case location where the .cfg is not available*). Note: we don't password protect our desktops hence the need for #3.

4) Backdoor password access.. one that doesn't change the password set. In the past we use a decimal to octal conversion routine: The title bar of the password box has a random number, that if you type it into a calculator and hit the OCTAL button, then type in the octal equivalent into the password box it unlocks. This is not a password or function our desktops use or understand exists, but we know what to do. ie. If we type in "53824" and hit the OCT button, the result is 151100. If you type that in the password box, or the actual user password, it'll unlock.

5) When Screensaver is active, it must be able to allow forced shutdowns and restarts from outside sources/processes such as, for example, desktop updates.

So any coding help on these would be massively appreciated! The above are the most critical features to be added.

Thank you AutoIT Community!!

Edited by Thudo

Share this post


Link to post
Share on other sites



Many people would be happy to help you, but we aren't here to just make custom programs per your request. If you attempt to do what you want on your own, you can come to us if/when you get stuck.

I recommend reading the helpfile too.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks Paulie.. sorry I need to take this slowly then..

Ok my main problems having edited the code are as follows:

1) I've added a 4th line to the cfg file for idle time outs. When I try to call it the screensaver simply keeps running and I have to end-task it. Not sure whats wrong. Notice this under "Func _IdleTicks()" which has been edited.

2) I still have yet to figure how to use _MouseTrap when then "password box" comes up -- essentially I have tried to freeze the screen around the password area but doesn't work. No sense in having the user unlock the screensaver when they can use the windows behind the password box.

3) Storing the password to unlock will be the 5th line -- you'll notice there is now an "Func _AskPassword()" now but how to relate to that 5th line so it will check the cfg file for that password and when the user types the right one it unlocks it -- this part I have no clue.

4) Anyone recommend a proper "password box" where a user can type the password into it? I'm still learning GUI structure.

Here is my updated script:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=d3mon Corporation\Autoit\ICON\SHELL32\016_shell32.ico
#AutoIt3Wrapper_outfile=ScreenSaver.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseAnsi=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Determine cfg paths
Local $TempDir=("\\<network_path>\")        ; network path to cfg 
Local $TempDir2=("C:\DATA\")            ; local path to cfg (used as backup)

; Ensure network path is always backed-up to local path.
If FileExists($TempDir) then
FileCopy($TempDir, $TempDir2, 1)
endif

; Choose alternate path if primary does not exist
If Not FileExists($TempDir) then
    Local $sav = $TempDir2 & '\ScreenSaver.cfg', $lticks, $GUI, $CGUI, $bl_ScreenSaver = False
    Local $sav = $TempDir2 & '\ScreenSaver.cfg', $lticks
    Local $w = @DesktopWidth, $h = @DesktopHeight, $sPath = FileReadLine($sav, 1)
Else
    Local $sav = $TempDir & '\ScreenSaver.cfg', $lticks, $GUI, $CGUI, $bl_ScreenSaver = False
    Local $sav = $TempDir & '\ScreenSaver.cfg', $lticks
    Local $w = @DesktopWidth, $h = @DesktopHeight, $sPath = FileReadLine($sav, 1)
endif
Opt('GUIOnEventMode', 1)

; Set Hotkey to invoke password
HotKeySet("^!{s}", "_ScreenSaverHotKey")    ; Ctrl+Alt+S 

#Region Check cfg
If Not FileExists($sav) Then
    FileWrite($sav, "C:\DATA\SCREENSAVER\") ; where the images are stored
    FileWrite($sav, @CRLF & '5000') ; Time in ms between image transitions (standard is 15 seconds)
    FileWrite($sav, @CRLF & '.bmp|.jpg|.gif')   ; Image formats supported
    FileWrite($sav, @CRLF & '5000') ; Time in ms between idle timeouts
    FileWrite($sav, @CRLF & "test") ; default password to unlock screensaver
EndIf
#EndRegion Check cfg

#Region Pref GUI
$PGUI = GUICreate('Picture Screen Saver - d3monCorp', 260, 150, -1, -1, BitOR(0x00040000, 0x00000080))
GUISetOnEvent(-3, '_PrefClose')

GUICtrlCreateGroup('Pictures folder', 5, 5, 245, 42)
$p_pic = GUICtrlCreateEdit(FileReadLine($sav, 1), 10, 20, 170, 20, 2048 + 128)
GUICtrlCreateButton('Browse', 190, 20, 50, 20)
GUICtrlSetOnEvent(-1, '_Browse')

GUICtrlCreateGroup('Display picture extension...', 5, 50, 155, 40)
$bmp = GUICtrlCreateCheckbox('.bmp', 15, 65)
$jpg = GUICtrlCreateCheckbox('.jpg', 70, 65)
$gif = GUICtrlCreateCheckbox('.gif', 120, 65)

GUICtrlCreateGroup('Display time', 170, 50, 80, 40)
$tdisp = GUICtrlCreateEdit(FileReadLine($sav, 2), 180, 67, 60, 17, 8192 + 128)

; Need to correct this as GUI box is not yet set.
GUICtrlCreateGroup('Idle timeout', 170, 50, 80, 40)
$tidle = GUICtrlCreateEdit(FileReadLine($sav, 4), 180, 67, 60, 17, 8192 + 128)

GUICtrlCreateButton('Apply', 80, 100, 80, 20)
GUICtrlSetOnEvent(-1, '_PrefApply')
GUISetState(@SW_HIDE, $PGUI)
#EndRegion Pref GUI

If Not @Compiled Then ; Run ScreenSaver if not compiled
    _WinAPI_ShowCursor(0)
    _ScreenSaverPicture($w, $h)
Else
    If Not $CmdLine[0] Then Exit ConsoleWrite('!> $CmdLine[0]' & @CRLF) ; Exit if no CmdLine
    
    If StringInStr($CmdLine[1], '/p') Then
        If $CmdLine[0] < 2 Then Exit MsgBox(48, 'Picture scr', 'Invalid preview window information supplied.')
        $parent_PID = _ProcessGetParent(@AutoItPID)
        _ScreenSaverPicture(152, 112, HWnd($CmdLine[2]))
    ElseIf StringInStr($CmdLine[1], '/s') Then
        _WinAPI_ShowCursor(0)
        _ScreenSaverPicture($w, $h)
    Else
        _PrefOpen()
    EndIf
EndIf

#Region Pref Func
Func _Browse()
    $path = FileSelectFolder('Select picture folder', @MyDocumentsDir, 1 + 2)
    If @error Then Exit ConsoleWrite('!> FileSelectFolder' & @CRLF)
    GUICtrlSetData($p_pic, $path & '\')
EndFunc   ;==>_Browse

Func _PrefApply()
    FileDelete($sav)
    FileWrite($sav, GUICtrlRead($p_pic))
    If (GUICtrlRead($tdisp) <> '') Then FileWrite($sav, @CRLF & GUICtrlRead($tdisp) & @CRLF)
    If (GUICtrlRead($tdisp) = '') Then FileWrite($sav, @CRLF & '2000' & @CRLF)
    If (GUICtrlRead($tidle) <> '') Then FileWrite($sav, @CRLF & GUICtrlRead($tidle) & @CRLF)
    If (GUICtrlRead($tidle) = '') Then FileWrite($sav, @CRLF & '2000' & @CRLF)
    If (GUICtrlRead($bmp) = 1) Then FileWrite($sav, '.bmp|')
    If (GUICtrlRead($jpg) = 1) Then FileWrite($sav, '.jpg|')
    If (GUICtrlRead($gif) = 1) Then FileWrite($sav, '.gif|')
    Return Call('_PrefClose')
EndFunc   ;==>_PrefApply

Func _PrefOpen()
    GUICtrlSetData($p_pic, FileReadLine($sav, 1))
    GUICtrlSetData($tdisp, FileReadLine($sav, 2))
    $sExt = StringSplit(FileReadLine($sav, 3), '|')
    
    #Region Reset checkbox
    GUICtrlSetState($bmp, 4)
    GUICtrlSetState($jpg, 4)
    GUICtrlSetState($gif, 4)
    #EndRegion Reset checkbox
    
    For $i = 1 To UBound($sExt) - 1
        If ($sExt[$i] = '.bmp') Then
            GUICtrlSetState($bmp, 1)
        ElseIf ($sExt[$i] = '.jpg') Then
            GUICtrlSetState($jpg, 1)
        ElseIf ($sExt[$i] = '.gif') Then
            GUICtrlSetState($gif, 1)
        EndIf
    Next
    GUISetState(@SW_SHOW, $PGUI)
EndFunc   ;==>_PrefOpen

Func _PrefClose()
    Exit GUISetState(@SW_HIDE, $PGUI)
EndFunc   ;==>_PrefClose
#EndRegion Pref Func

While 1
    Sleep(250)
WEnd

Func OnAutoItExit()
    _WinAPI_ShowCursor(1)
EndFunc   ;==>OnAutoItExit

Func _ScreenSaverHotKey()
    _WinAPI_ShowCursor(0)
    _ScreenSaverPicture($w, $h)
EndFunc

; Needs to read line 5 in config file for password
Func _AskPassword()
    _StopScreenSaver()
    MsgBox(64, "", "Enter Password")
EndFunc

Func _StopScreenSaver()
    $bl_ScreenSaver = False
    GUIDelete($CGUI)
    GUIDelete($GUI)
    _WinAPI_ShowCursor(1)
EndFunc

; _ScreenSaverPicture
Func _ScreenSaverPicture($width, $height, $hwnd = 'Screen Saver')
    $bl_ScreenSaver = True

    If ($hwnd = 'Screen Saver') Then
        Global $GUI = GUICreate('Screen Saver', @DesktopWidth, @DesktopHeight, 0, 0, 0x80000000)
;~      $GUI = GUICreate('Screen Saver', @DesktopWidth, @DesktopHeight, 0, 0, 0x80000000)
        GUISetBkColor(0x000000, $GUI)
        GUISetState(@SW_SHOW, $GUI)
        WinSetOnTop($GUI, "", 1)
;~      WinSetOnTop($GUI, '', 1)
    EndIf
    Global $CGUI = GUICreate('Screen Saver', $width, $height, 0, 0, 0x80000000, 0x00000008, $hwnd)
;~  $CGUI = GUICreate('Screen Saver', $width, $height, 0, 0, 0x80000000, 0x00000008, $hwnd)
    _WinAPI_SetParent($CGUI, $hwnd)
    $PIC = GUICtrlCreatePic('', 0, 0, $width, $height)
    GUISetBkColor(0x000000, $CGUI)
    GUISetState(@SW_SHOW, $CGUI)
    
    Local $s_path = FileReadLine($sav, 1)
    Local $n_disp = FileReadLine($sav, 2)
    Local $bmp = False, $jpg = False, $gif = False
    $sExt = StringSplit(FileReadLine($sav, 3), '|')
    
    For $i = 1 To UBound($sExt) - 1
        If ($sExt[$i] = '.bmp') Then
            $bmp = True
        ElseIf ($sExt[$i] = '.jpg') Then
            $jpg = True
        ElseIf ($sExt[$i] = '.gif') Then
            $gif = True
        EndIf
    Next
    
    While $bl_ScreenSaver = True
;~  While 1
        $check = FileFindFirstFile($s_path & '*.*')
        If $check = -1 Then Exit ConsoleWrite('!> FileFindFirstFile' & Chr(13))
        While $bl_ScreenSaver = True
;~      While 1
            Sleep(300)
            $sNext = FileFindNextFile($check)
            If @error Then ExitLoop ; Go to the first file
            $s_Ext = StringRegExpReplace($sNext, '^.*\.', '')
            
            If ($hwnd = 'Screen Saver') Then
;~              If _IdleTicks() Then Exit ;Mouse/Keyboard event
                If _IdleTicks() Then _AskPassword()
            Else
                $child_PID = _ProcessGetChildren($parent_PID)
                If $child_PID[0] > 1 Then Exit ;Another ss selected
                If Not WinExists($hwnd) Then Exit
            EndIf
            
            If ($s_Ext = 'bmp') And $bmp = True Then
                __SetPicture($CGUI, $PIC, $s_path & $sNext, $n_disp, $hwnd)
            ElseIf ($s_Ext = 'jpg') And $jpg = True Then
                __SetPicture($CGUI, $PIC, $s_path & $sNext, $n_disp, $hwnd)
            ElseIf ($s_Ext = 'gif') And $gif = True Then
                __SetPicture($CGUI, $PIC, $s_path & $sNext, $n_disp, $hwnd)
            EndIf
        WEnd
        ConsoleWrite('!> FileFindNextFile' & Chr(13))
    WEnd
EndFunc   ;==>_ScreenSaverPicture

; Edit how the screensaver cycles images (currently set to "1")
Func __SetPicture($hGUI, $ID, $p_path, $idisp, $hwnd)
    GUICtrlSetImage($ID, $p_path)
    ;_WinAnimate($hGUI, Random(1, 10, 1), 1, 700)
    _WinAnimate($hGUI, 1, 1, 700)
    $Init = TimerInit()
    While 1
        Sleep(300)
        If ($hwnd = 'Screen Saver') Then
;~          If _IdleTicks() Then Exit ;Mouse/Keyboard event
            If _IdleTicks() Then _AskPassword()
        Else
            $child_PID = _ProcessGetChildren($parent_PID)
            If $child_PID[0] > 1 Then Exit ;Another ss selected
            If Not WinExists($hwnd) Then Exit
        EndIf
        If TimerDiff($Init) > $idisp Then ExitLoop
    WEnd
    ;_WinAnimate($hGUI, Random(1, 10, 1), 2, 500)
    _WinAnimate($hGUI, 1, 2, 500)
EndFunc   ;==>__SetPicture

; _WinAPI_SetParent
Func _WinAPI_SetParent($hWndChild, $hWndParent)
    Local $aResult

    $aResult = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $hWndParent)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_SetParent

; _WinAPI_ShowCursor
Func _WinAPI_ShowCursor($fShow)
    Local $aResult
    $aResult = DllCall('User32.dll', 'int', 'ShowCursor', 'int', $fShow)
    If @error Then Return SetError(@error, 0, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_ShowCursor

; _WinAnimate
Func _WinAnimate($hGUI, $Style = 1, $Ani = 1, $n_speed = 250)
    Local $sIN = StringSplit('80000,40001,40002,40004,40008,40005,40006,40009,4000A,40010', ',')
    Local $sOUT = StringSplit('90000,50002,50001,50008,50004,5000A,50009,50006,50005,50010', ',')
    If $Ani = 1 Then
        DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGUI, 'int', $n_speed, 'long', '0x000' & $sIN[$Style])
    ElseIf $Ani = 2 Then
        DllCall('user32.dll', 'int', 'AnimateWindow', 'hwnd', $hGUI, 'int', $n_speed, 'long', '0x000' & $sOUT[$Style])
    EndIf
EndFunc   ;==>_WinAnimate

;~ ; _IdleTicks
;~ Func _IdleTicks()
;~  Local $aTSB = DllCall('kernel32.dll', 'long', 'GetTickCount')
;~  Local $ticksSinceBoot = $aTSB[0]
;~  Local $struct = DllStructCreate('uint;dword')
;~  DllStructSetData($struct, 1, DllStructGetSize($struct))
;~  DllCall('user32.dll', 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($struct))
;~  Local $ticksSinceIdle = DllStructGetData($struct, 2)
;~  If ($ticksSinceBoot - $ticksSinceIdle) < $lticks Then Return 1
;~  $lticks = ($ticksSinceBoot - $ticksSinceIdle)
;~     ;Return ($ticksSinceBoot - $ticksSinceIdle)
;~ EndFunc   ;==>_IdleTicks

Func _IdleTicks()
;~  ;Dim $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // only for example then you will read this value in the config file
    Local $h_GTC = DllCall('kernel32.dll', 'long', 'GetTickCount')
    Local $i_Ticks_Init = $h_GTC[0]
    Local $struct = DllStructCreate('uint;dword')
    Local $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // read from value in the config file
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall('user32.dll', 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($struct))
    Local $i_TicksSinceIdle = DllStructGetData($struct, 2)

    If ($i_Ticks_Init - $i_TicksSinceIdle) > $i_WaitIdleTime Then
        MsgBox(64, "", "Now we can start the screensaver")
    EndIf
EndFunc  ;==>_IdleTicks

; _ProcessGetParent
Func _ProcessGetParent($i_pid)
    Local $TH32CS_SNAPPROCESS = 0x00000002
    
    Local $a_tool_help = DllCall('Kernel32.dll', 'long', 'CreateToolhelp32Snapshot', 'int', $TH32CS_SNAPPROCESS, 'int', 0)
    If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_pid)
    
    Local $tagPROCESSENTRY32 = _
            DllStructCreate( _
            'dword dwsize;' & _
            'dword cntUsage;' & _
            'dword th32ProcessID;' & _
            'uint th32DefaultHeapID;' & _
            'dword th32ModuleID;' & _
            'dword cntThreads;' & _
            'dword th32ParentProcessID;' & _
            'long pcPriClassBase;' & _
            'dword dwFlags;' & _
            'char szExeFile[260]' _
            )
    DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32))
    
    Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32)
    
    Local $a_pfirst = DllCall('Kernel32.dll', 'int', 'Process32First', 'long', $a_tool_help[0], 'ptr', $p_PROCESSENTRY32)
    If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_pid)
    
    Local $a_pnext, $i_return = 0
    If DllStructGetData($tagPROCESSENTRY32, 'th32ProcessID') = $i_pid Then
        $i_return = DllStructGetData($tagPROCESSENTRY32, 'th32ParentProcessID')
        DllCall('Kernel32.dll', 'int', 'CloseHandle', 'long', $a_tool_help[0])
        If $i_return Then Return $i_return
        Return $i_pid
    EndIf
    
    While @error = 0
        $a_pnext = DllCall('Kernel32.dll', 'int', 'Process32Next', 'long', $a_tool_help[0], 'ptr', $p_PROCESSENTRY32)
        If DllStructGetData($tagPROCESSENTRY32, 'th32ProcessID') = $i_pid Then
            $i_return = DllStructGetData($tagPROCESSENTRY32, 'th32ParentProcessID')
            If $i_return Then ExitLoop
            $i_return = $i_pid
            ExitLoop
        EndIf
    WEnd
    DllCall('Kernel32.dll', 'int', 'CloseHandle', 'long', $a_tool_help[0])
    Return $i_return
EndFunc   ;==>_ProcessGetParent

; _ProcessGetChildren
Func _ProcessGetChildren($i_pid)
    Local Const $TH32CS_SNAPPROCESS = 0x00000002
    
    Local $a_tool_help = DllCall('Kernel32.dll', 'long', 'CreateToolhelp32Snapshot', 'int', $TH32CS_SNAPPROCESS, 'int', 0)
    If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_pid)
    
    Local $tagPROCESSENTRY32 = _
            DllStructCreate _
            ( _
            'dword dwsize;' & _
            'dword cntUsage;' & _
            'dword th32ProcessID;' & _
            'uint th32DefaultHeapID;' & _
            'dword th32ModuleID;' & _
            'dword cntThreads;' & _
            'dword th32ParentProcessID;' & _
            'long pcPriClassBase;' & _
            'dword dwFlags;' & _
            'char szExeFile[260]' _
            )
    DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32))
    
    Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32)
    
    Local $a_pfirst = DllCall('Kernel32.dll', 'int', 'Process32First', 'long', $a_tool_help[0], 'ptr', $p_PROCESSENTRY32)
    If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_pid)
    
    Local $a_pnext, $a_children[11] = [10], $i_child_pid, $i_parent_pid, $i_add = 0
    $i_child_pid = DllStructGetData($tagPROCESSENTRY32, 'th32ProcessID')
    If $i_child_pid <> $i_pid Then
        $i_parent_pid = DllStructGetData($tagPROCESSENTRY32, 'th32ParentProcessID')
        If $i_parent_pid = $i_pid Then
            $i_add += 1
            $a_children[$i_add] = $i_child_pid
        EndIf
    EndIf
    
    While 1
        $a_pnext = DllCall('Kernel32.dll', 'int', 'Process32Next', 'long', $a_tool_help[0], 'ptr', $p_PROCESSENTRY32)
        If IsArray($a_pnext) And $a_pnext[0] = 0 Then ExitLoop
        $i_child_pid = DllStructGetData($tagPROCESSENTRY32, 'th32ProcessID')
        If $i_child_pid <> $i_pid Then
            $i_parent_pid = DllStructGetData($tagPROCESSENTRY32, 'th32ParentProcessID')
            If $i_parent_pid = $i_pid Then
                If $i_add = $a_children[0] Then
                    ReDim $a_children[$a_children[0] + 10]
                    $a_children[0] = $a_children[0] + 10
                EndIf
                $i_add += 1
                $a_children[$i_add] = $i_child_pid
            EndIf
        EndIf
    WEnd
    
    If $i_add <> 0 Then
        ReDim $a_children[$i_add + 1]
        $a_children[0] = $i_add
    EndIf
    
    DllCall('Kernel32.dll', 'int', 'CloseHandle', 'long', $a_tool_help[0])
    If $i_add Then Return $a_children
    Return SetError(3, 0, 0)
EndFunc   ;==>_ProcessGetChildren

Any help would be most appreciated. I'm still learning some of this more advanced functionality. :blink:

TuD.

Edited by Thudo

Share this post


Link to post
Share on other sites

Ok I think I got #3 and 4 sorted in the list. Using an MD5 Encryption and storing the hash in the cfg. GUI box works well for what it is.

I'm still a little dumbfounded with the _Idleticks and _MouseTrap functions.

For Idleticks it was suggested to use this to determine how long to wait to bring up the screensaver when no activity was determined:

Func _IdleTicks()
;~  ;Dim $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // only for example then you will read this value in the config file
    Local $h_GTC = DllCall('kernel32.dll', 'long', 'GetTickCount')
    Local $i_Ticks_Init = $h_GTC[0]
    Local $struct = DllStructCreate('uint;dword')
    Local $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // read from value in the config file
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall('user32.dll', 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($struct))
    Local $i_TicksSinceIdle = DllStructGetData($struct, 2)

    If ($i_Ticks_Init - $i_TicksSinceIdle) > $i_WaitIdleTime Then
        MsgBox(64, "", "Now we can start the screensaver")
    EndIf
EndFunc  ;==>_IdleTicks
But if I use that then the screensaver never brings up the password box and just stays at a black screen. "(FileReadLine($sav, 4))" is set to read the 4th line of the cfg so its set to 10sec.

As for the MouseTrap so it freezes the Password screen so only the user can type inside the box.. this code was suggested:

Func _MouseTrapCurrent()         
    Opt("MouseCoordMode",0)         
    $local = MouseGetPos()         
        _MouseTrap($local[0],$local[1])         
    Opt("MouseCoordMode",2) 
EndFunc
..however where does it go?

The Password box comes up using this function:

; Hash Password check facility
Func _PasswordCheck()
$bPasswordHash=(FileReadLine($sav, 5)) 
$sPassword=InputBox("Login","Enter Password.","")
If _Crypt_HashData($sPassword,$CALG_MD5)=$bPasswordHash Then
Else
    MsgBox(16,"Access Denied","Password Incorrect!")
EndIf
EndFunc
Any help is most appreciated!

Share this post


Link to post
Share on other sites

This AutoIT versus AutoIt use seems to be very contagious ... or maybe it only seems to be that way ... :blink: (Re-Filing it to ignore cabinet.)


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

hehe... yeah sorry.. Autoit.. AutoIT is an oxymoron. :blink:

So my question apart from the _IdleTicks above..

How do you use _Mousetrap to lock the user inside a current window? ie.. I have a password box called "Login" which comes up and I want to freeze all mouse/keyboard to inside that box until the password is correct. Not worrying about Ctrl-Alt-Delete currently right now to unlock (although is that even possible to prevent as well)?

Thanks everyone..

Edited by Thudo

Share this post


Link to post
Share on other sites

Ok at a crossroads here and really need the autoit community on this one:

1) Code for determining when the screensaver should show the images after being idle for a determined time:

Func _IdleTicks()
;~  ;Dim $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // only for example then you will read this value in the config file
    Local $h_GTC = DllCall('kernel32.dll', 'long', 'GetTickCount')
    Local $i_Ticks_Init = $h_GTC[0]
    Local $struct = DllStructCreate('uint;dword')
    Local $i_WaitIdleTime = (FileReadLine($sav, 4)) ; 10*1000 ;=10sec (ms) // read from value in the config file
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall('user32.dll', 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($struct))
    Local $i_TicksSinceIdle = DllStructGetData($struct, 2)

    If ($i_Ticks_Init - $i_TicksSinceIdle) > $i_WaitIdleTime Then
        MsgBox(64, "", "Now we can start the screensaver")
    EndIf
EndFunc  ;==>_IdleTicks
The above basically causes the screensaver (I'm not compling it at this point just running it from Autoit) to not respond to the mouse to bring up the password. It just goes to a black screen and stays there. Whats the problem?

2) I'm understanding _MouseTrap now except no idea why it won't enable when the password box comes up to confine the user there.

Basically trying to get this code to work when the "login" box comes up but never works except after it.

AdlibRegister("_MouseTrapCurrent")
Func _MouseTrapCurrent()
If WinExists("Login") then
_MouseTrap(550,500,750,600)
else
_MouseTrap()
    endif
EndFunc
If you want me to post all the code I will in-case something is not clear.

I feel I'm getting really close with the whole project just making additional refinements which satisfy the security team.

Thanks everyone!

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