Jump to content

Using MouseTrap to freeze both keyboard/mouse at password prompt


Recommended Posts

I've seen this brought up before but never found a workable solution.

I want to have a user be forced into a confined spot on the desktop (both mouse and keyboard) when a certain window comes up.

My code sofar:

AdlibRegister("_MouseTrapCurrent")
Func _MouseTrapCurrent()
If WinExists("Login") then
_MouseTrap(550,500,750,600)
else
_MouseTrap()
    endif
EndFunc
So essentially when the window "login" comes up it should mousetrap the mouse AND keyboard into a tiny spot. I haven't yet figured out how to lock the keyboard there also. :blink: What I've found with _MouseTrap is it always seems to work after the Login prompt but never during. Grr.. Anyone have a suggestion? Getting real critical at this stage. I can post more of the code if necessary.

Thanks to the Autoit community!

Link to comment
Share on other sites

  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

; Function:
#include <Misc.au3>
Func _MouseTrapCurrent($hWin)
    If WinExists($hWin) Then
        $Pos = WinGetPos($hWin)
        If Not @error Then
            _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
        EndIf
    Else
        _MouseTrap()
    Endif
EndFunc
; Example:
While 1
    _MouseTrapCurrent('Untitled - Notepad')
WEnd

Link to comment
Share on other sites

Thanks EPDMK..

Works great except one thing: how do I integrate this into my full code? It works as standalone but when I put it into my entire code it doesn't ever run.

Also, I gather I can run it under different function headings to keep the mouse to different box names as such:

Func _MouseTrapDenied($hWin)
    If WinExists($hWin) Then
        $Pos = WinGetPos($hWin)
        If Not @error Then
            _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
        EndIf
    Else
        _MouseTrap()
    Endif
EndFunc
While 1
    _MouseTrapDenied('Access Denied')
WEnd

Func _MouseTrapLimitReached($hWin)
    If WinExists($hWin) Then
        $Pos = WinGetPos($hWin)
        If Not @error Then
            _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
        EndIf
    Else
        _MouseTrap()
    Endif
EndFunc
While 1
    _MouseTrapLimitReached('Failed Password Login attempt limit reached')
WEnd
So the user is continuously stuck inside each box so there is no escape until its successfully unlocked. :blink:

So I am wondering where to run your script in my code? Is there a way to prioritize it in the hierarchy so its always checking for those prompt boxes?

Link to comment
Share on other sites

No sir.. but this is:

#NoTrayIcon
#include <Crypt.au3>
#include <GuiConstantsEx.au3>
#include <Misc.au3>
#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 ****

;~ AdlibRegister("_MouseTrapCurrent")

; 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("^!{l}", "_ScreenSaverHotKey")    ; Ctrl+Alt+L 

#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 (standard is 7 mins)
    FileWrite($sav, @CRLF & "<password>")   ; default Hash password to unlock screensaver (in MD5 Encyption)
    FileWrite($sav, @CRLF & "<password>")   ; master unchanging Hash password to unlock screensaver for support teams (in MD5 Encyption)
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 _MouseTrapLogin($hWin)
;~     If WinExists($hWin) Then
;~         $Pos = WinGetPos($hWin)
;~         If Not @error Then
;~             _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
;~         EndIf
;~     Else
;~         _MouseTrap()
;~     Endif
;~ EndFunc
;~ While 1
;~     _MouseTrapLogin('Login')
;~ WEnd

Func _MouseTrapCurrent($hWin)
    If WinExists($hWin) Then
        $Pos = WinGetPos($hWin)
        If Not @error Then
            _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
        EndIf
    Else
        _MouseTrap()
    Endif
EndFunc
While 1
    _MouseTrapCurrent('Login')
WEnd

;~ Func _MouseTrapDenied($hWin)
;~     If WinExists($hWin) Then
;~         $Pos = WinGetPos($hWin)
;~         If Not @error Then
;~             _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
;~         EndIf
;~     Else
;~         _MouseTrap()
;~     Endif
;~ EndFunc
;~ While 1
;~     _MouseTrapDenied('Access Denied')
;~ WEnd

;~ Func _MouseTrapLimitReached($hWin)
;~     If WinExists($hWin) Then
;~         $Pos = WinGetPos($hWin)
;~         If Not @error Then
;~             _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
;~         EndIf
;~     Else
;~         _MouseTrap()
;~     Endif
;~ EndFunc
;~ While 1
;~     _MouseTrapLimitReached('Failed Password Login attempt limit reached')
;~ WEnd

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

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

; Initiates password facility
Func _AskPassword()
    _StopScreenSaver()
    _PasswordCheck()
EndFunc

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

Switch _PasswordCheck()
    Case 1
        MsgBox(0, "Result", "Login Correct")
    Case 0
        MsgBox(0, "Result", "Login Cancelled ")
    case -1
        MsgBox(0, "Result", "Failed 5 times lock out user")
EndSwitch

Func _PasswordCheck()
    Local $iXTimes = 5, $iCount = 1
    While 1
        Local $bPasswordHash=(FileReadLine($sav, 5))
        Local $bMasterPasswordHash=(FileReadLine($sav, 6)) 
        Local $sPassword=InputBox("Login","Enter Password      "&(FileReadLine($sav, 5)),"",'',320,100) ; displays current live hash data to user.
        If _Crypt_HashData($sPassword,$CALG_MD5)="0x"&$bPasswordHash or _Crypt_HashData($sPassword,$CALG_MD5)="0x"&$bMasterPasswordHash Then Return $sPassword 
        Select
            Case $sPassword = "Correct"
                Return 1
            Case $iCount = $iXTimes
                BlockInput(1)   ; Freeze user's mouse/keyboard -- likely will omit this but here for testing the lock down.
                MsgBox(16, "Failed Password Login attempt limit reached", "Please ask for Assistance..")
                Return -1
            Case Else
                MsgBox(16, "Access Denied", "Password Incorrect!" & @CR & "You have " & $iXTimes - $iCount & " trys left")
                $iCount += 1
        EndSelect
WEnd
EndFunc   ;==>_PasswordCheck

; _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
Link to comment
Share on other sites

I quick look.

While 1

Sleep(250)

WEnd

comes before

While 1

_MouseTrapCurrent('Login')

WEnd

so its unlikely the second loop is ever reached

Then you have adlibregister trying to run the sme function that is in the second while loop.

The function _MouseTrapCurrent() expects a parameter also, which adlibresister dosent pass to it.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I quick look.

While 1

Sleep(250)

WEnd

comes before

While 1

_MouseTrapCurrent('Login')

WEnd

so its unlikely the second loop is ever reached

I disabled that first While 1 you mentioned.. no effect.

Then you have adlibregister trying to run the sme function that is in the second while loop.

The function _MouseTrapCurrent() expects a parameter also, which adlibresister dosent pass to it.

Not sure you saw but AdlibRegister is disabled in the code"

;~ AdlibRegister("_MouseTrapCurrent")

Also, AdlibRegister won't work for _MouseTrapCurrent($hWin) since it has that "($hWin)" at the end of it. :|

Link to comment
Share on other sites

Hmm.. not sure what else I can do to compress the full code in #7.. its all there.

However the issue is with all this code when the screensaver comes out of showing its images and then the password prompt comes up (the following):

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

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

; Initiates password facility
Func _AskPassword()
    _StopScreenSaver()
    _PasswordCheck()
EndFunc

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

Switch _PasswordCheck()
    Case 1
        MsgBox(0, "Result", "Login Correct")
    Case 0
        MsgBox(0, "Result", "Login Cancelled ")
    case -1
        MsgBox(0, "Result", "Failed 5 times lock out user")
EndSwitch

Func _PasswordCheck()
    Local $iXTimes = 5, $iCount = 1
    While 1
        Local $bPasswordHash=(FileReadLine($sav, 5))
        Local $bMasterPasswordHash=(FileReadLine($sav, 6)) 
        Local $sPassword=InputBox("Login","Enter Password      "&(FileReadLine($sav, 5)),"",'',320,100) ; displays current live hash data to user.
        If _Crypt_HashData($sPassword,$CALG_MD5)="0x"&$bPasswordHash or _Crypt_HashData($sPassword,$CALG_MD5)="0x"&$bMasterPasswordHash Then Return $sPassword 
        Select
            Case $sPassword = "Correct"
                Return 1
            Case $iCount = $iXTimes
                BlockInput(1)   ; Freeze user's mouse/keyboard -- likely will omit this but here for testing the lock down.
                MsgBox(16, "Failed Password Login attempt limit reached", "Please ask for Assistance..")
                Return -1
            Case Else
                MsgBox(16, "Access Denied", "Password Incorrect!" & @CR & "You have " & $iXTimes - $iCount & " trys left")
                $iCount += 1
        EndSelect
WEnd
EndFunc   ;==>_PasswordCheck
This is the section where _MouseTrap needs to confine the user. It works if I compiled this as an exe and have it running in the background:

Func _MouseTrapCurrent($hWin)
    If WinExists($hWin) Then
        $Pos = WinGetPos($hWin)
        If Not @error Then
            _MouseTrap($Pos[0], $Pos[1], $Pos[0] + $Pos[2], $Pos[1] + $Pos[3])
        EndIf
    Else
        _MouseTrap()
    Endif
EndFunc
; Example:
While 1
    _MouseTrapCurrent('Login')
WEnd
but it needs to be part of the larger code in #7 and not as seperate autoit exes running in the background. Thats why if it could be integrated into the master autoit code in #7 that would rock!
Link to comment
Share on other sites

MsgBox() is a blocking function itself, meaning your other functions are not running while a msgbox is showing.

Try using your own gui instead of a msgbox and see if that makes a difference.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Try using your own gui instead of a msgbox and see if that makes a difference.

You'll forgive my complete dumbness but what other GUI? Is there an Autoit alternative built inside itself apart from its standard one?
Link to comment
Share on other sites

Ah so like:

$PGUI = GUICreate('Login', 280, 150, -1, -1, BitOR(0x00040000, 0x00000080))
GUISetOnEvent(-3, '_PrefClose')
$pass = GUICtrlCreateEdit("", 180, 67, 60, 17, 8192 + 128)
Yeah thats doable.. just had everything stable with MsgBox but now have to re-do it all with a GUI. ;)

Still.. can _MouseTrap detect the GUI box apart from a MsgBox? Gather so.. :blink:

Edited by Thudo
Link to comment
Share on other sites

Its not quite the same, a user gui wont block the code the same as a msgbox.

If you try MsgBox(0,"","") in a script on its own, and run it, then try to end the script via the system tray, you will notice it wont end until you click the box.

With a user gui it will end.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Case $iCount = $iXTimes
                BlockInput(1)   ; Freeze user's mouse/keyboard -- likely will omit this but here for testing the lock down.
                MsgBox(16, "Failed Password Login attempt limit reached", "Please ask for Assistance..")
                Return -1

That will block your mousetrap function, while wiating for input.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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