Thudo Posted August 6, 2010 Author Posted August 6, 2010 Ok nearly there. With the help of others I've created this: expandcollapse popup#include <Misc.au3> Opt('GUIOnEventMode', 1) #Region Pref GUI $PGUI = GUICreate('Login', 170, 110, -1, -1, BitOR(0x00040000, 0x00000080)) GUISetOnEvent(-3, '_PrefClose') GUICtrlCreateGroup('Enter Password', 5, 10, 155, 40) $password = GUICtrlCreateInput("", 10, 25, 145, 20, 0x0020) ; $ES_PASSWORD style <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateButton('Apply', 55, 55, 50, 20) GUICtrlSetOnEvent(-1, '_PrefClose') GUISetState(@SW_HIDE, $PGUI) #EndRegion Pref GUI ; Always run the application _PrefOpen() 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 _PrefOpen() GUISetState(@SW_SHOW, $PGUI) EndFunc ;==>_PrefOpen Func _PrefClose() Exit GUISetState(@SW_HIDE, $PGUI) EndFunc ;==>_PrefClose #EndRegion Pref Func While 1 Sleep(10) WEnd Which basically freezes the mouse into the password box perfectly as it should. However.. I cannot get to work within this: expandcollapse popupFunc _PasswordOpen() $PASSGUI = GUICreate('Login', 170, 110, -1, -1, BitOR(0x00040000, 0x00000080)) GUISetOnEvent(-3, '_PasswordClose') GUICtrlCreateGroup('Enter Password', 5, 10, 155, 40) Global $password = GUICtrlCreateInput("", 10, 25, 145, 20, 0x0020) ; $ES_PASSWORD style <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateButton('OK', 55, 55, 50, 20) GUICtrlSetOnEvent(-1, '_PasswordCheck') GUISetState(@SW_HIDE, $PASSGUI) GUISetState(@SW_SHOW, $PASSGUI) EndFunc ;==>_PasswordOpen 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 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 _PasswordOpen() Local $bPasswordHash=(FileReadLine($sav, 5)) Local $bMasterPasswordHash=(FileReadLine($sav, 6)) $sPassWord = GUICtrlRead($password) If _Crypt_HashData($sPassword,$CALG_MD5)=$bPasswordHash or _Crypt_HashData($sPassword,$CALG_MD5)=$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 contact your local Associate or Front Store Manager for Assistance..") Return -1 Case Else MsgBox(16, "Access Denied", "Password Incorrect!" & @CR & "You have " & $iXTimes - $iCount & " trys left") $iCount += 1 EndSelect WEnd EndFunc ;==>_PasswordCheckThe Login GUI box is essentially conflicting with the PasswordCheck function by not working together AND also NOT freezing the mouse in the Login box as in the first code example. I'm also there just need some help merging both code bits together. The key was using a GUI rather than an InputBox which should then properly hold the mouse in place. This all has to work within the greater project. Thanks team!
Thudo Posted August 16, 2010 Author Posted August 16, 2010 Anyone able to determine the above? I seriously could use some code tweaks to the above from someone with a better eye than myself
Thudo Posted August 26, 2010 Author Posted August 26, 2010 Any thoughts on the above? Getting critical I need to figure this out. Really appreciate it, team!
Thudo Posted August 27, 2010 Author Posted August 27, 2010 (edited) I've updated the code bits with the latest build.. expandcollapse popup#include <Crypt.au3> #include <GuiConstantsEx.au3> #include <Misc.au3> #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=Screensaver.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:\") ; 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 & "0x098F6BCD4621D373CADE4E832627B4F6") ; default Hash password to unlock screensaver (in MD5 Encyption) FileWrite($sav, @CRLF & "0x6D662F965D1E85BB367EFAA03594C5A1") ; 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 _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 ;~ #Region Password GUI ;~ $PASSGUI = GUICreate('Login', 280, 150, -1, -1, BitOR(0x00040000, 0x00000080)) ;~ GUISetOnEvent(-3, '_PrefClose') ;~ GUICtrlCreateGroup('Enter Password', 5, 50, 155, 40) ;~ $password = GUICtrlCreateInput("", 10, 65, 145, 20, 0x0020) ; $ES_PASSWORD style <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;~ GUISetState(@SW_HIDE, $PASSGUI) ;~ #EndRegion Password GUI Func _PasswordOpen() $PASSGUI = GUICreate('Login', 170, 110, -1, -1, BitOR(0x00040000, 0x00000080)) ;~ GUISetOnEvent(-3, '_PasswordClose') GUICtrlCreateGroup('Enter Password', 5, 10, 155, 40) Global $password = GUICtrlCreateInput("", 10, 25, 145, 20, 0x0020) ; $ES_PASSWORD style <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateButton('OK', 55, 55, 50, 20) GUICtrlSetOnEvent(-1, '_PasswordCheck') GUISetState(@SW_HIDE, $PASSGUI) GUISetState(@SW_SHOW, $PASSGUI) EndFunc ;==>_PasswordOpen 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 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 _PasswordOpen() Local $bPasswordHash=(FileReadLine($sav, 5)) Local $bMasterPasswordHash=(FileReadLine($sav, 6)) ;~ $password = GUICtrlCreateInput("", 10, 25, 145, 20, 0x0020) ; $ES_PASSWORD style <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $sPassWord = GUICtrlRead($password) ;~ GUICtrlCreateGroup('Login', 5, 50, 155, 40) ;~ 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 If _Crypt_HashData($sPassword,$CALG_MD5)=$bPasswordHash or _Crypt_HashData($sPassword,$CALG_MD5)=$bMasterPasswordHash Then Return $sPassword Select Case $sPassword = "Correct" Return 1 Case $iCount = $iXTimes MsgBox(16, "Failed Password Login attempt limit reached", "Please contact your local support team 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 Put this in the C:\ drive and name it screensaver.cfg C:\ 5000 .bmp|.jpg|.gif 60000 0x136E264E94E5BE49096C7A54F33646B8 0x6D662F965D1E85BB367EFAA03594C5A1Password is "test". You can throw a single .bmp or .gif or .jpg file in C:\ to see the test. My main issue is the _Password check section and integrating the authentication system. Its borked and need help re-integrating it together so when a user types it in wrong it comes up with the warnings. Right now, its always giving a warning so I blew something here. Once thats done, the _MouseTrapCurrent($hWin) needs to freeze the mouse when the 'Login' box comes up. It doesn't work for some reason in this code so hope someone can see what I'm doing wrong. Thanks so very much. Hope someone can fix this asap! Edited August 27, 2010 by Thudo
Thudo Posted September 1, 2010 Author Posted September 1, 2010 Anyone willing to tackle this? I would so appreciate the help!
Thudo Posted September 2, 2010 Author Posted September 2, 2010 Ok to give you an idea what I am looking to do based on my requests above I created this mock-up of the login box+working mousetrap.. expandcollapse popup#include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('GUIOnEventMode', 1) Local $sav = ("C:\DATA\ScreenSaver.cfg") #Region Pref GUI $PASSGUI = GUICreate('Login', 330, 110, -1, -1, BitOR(0x00040000, 0x00000080)) GUISetOnEvent(-3, '_PrefClose') GUICtrlCreateGroup('Enter Password '&(FileReadLine($sav, 5)), 5, 10, 320, 40) $password = GUICtrlCreateInput("", 10, 25, 310, 20, 0x0020) ; $ES_PASSWORD style <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateButton('OK', 100, 55, 50, 20) GUICtrlSetOnEvent(-1, '_PrefClose') GUISetState(@SW_HIDE, $PASSGUI) GUICtrlCreateButton('Cancel', 185, 55, 50, 20) GUICtrlSetOnEvent(-1, '_PrefClose') GUISetState(@SW_HIDE, $PASSGUI) #EndRegion Pref GUI ; Always run the application _PrefOpen() 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 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)) If _Crypt_HashData($sPassword,$CALG_MD5)=$bPasswordHash or _Crypt_HashData($sPassword,$CALG_MD5)=$bMasterPasswordHash Then Return $sPassword Select Case $sPassword = "Correct" Return 1 Case $iCount = $iXTimes MsgBox(16, "Failed Password Login attempt limit reached", "Please contact your local Associate or Front Store Manager 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 Func _PrefOpen() GUISetState(@SW_SHOW, $PASSGUI) EndFunc ;==>_PrefOpen Func _PrefClose() Exit GUISetState(@SW_HIDE, $PASSGUI) EndFunc ;==>_PrefClose #EndRegion Pref Func While 1 Sleep(10) WEndI hope this gives an idea of how to move the _PasswordCheck over so its read by the GUI I've put in instead of the InputBox as this part is killing me.
Moderators Melba23 Posted September 3, 2010 Moderators Posted September 3, 2010 Thudo,You will never detect the "Login" InputBox - it is a blocking function and the rest of your script is suspended until it returns. You need to create a small GUI to do the same function which will let you detect it and then restrict the mouse - like this: #include <GUIConstantsEx.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) Global $hChild = 9999 $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit") $hButton = GUICtrlCreateButton("Log In", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "_LogIn") GUISetState() While 1 Sleep(10) WEnd Func On_Exit() Exit EndFunc Func _LogIn() $hChild = GUICreate("Log In", 200, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Child_Close") GUISetState() $aChildPos = WinGetPos($hChild) _MouseTrap($aChildPos[0], $aChildPos[1], $aChildPos[0] + $aChildPos[2], $aChildPos[1] + $aChildPos[3]) EndFunc Func _Child_Close() GUIDelete($hChild) _MouseTrap() EndFuncNow you have no detection problems - the mouse is trapped/untrapped when the GUI is created/deleted.I hope this helps. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
Thudo Posted September 3, 2010 Author Posted September 3, 2010 (edited) Thanks Melba.. one step closer except its not the GUI I couldn't create its how to merge the original Inputbox code over to GUI then ensure the _PasswordCheck() facility actually integrated like it did with the InputBox. Thats what has me cooked. Again, I am in your debt with this effort! Edited September 3, 2010 by Thudo
Moderators Melba23 Posted September 3, 2010 Moderators Posted September 3, 2010 Thudo,Try this in place of your current _PasswordCheck function:expandcollapse popupFunc _PasswordCheck() Local $iXTimes = 5, $iCount = 1 While 1 Local $bPasswordHash=(FileReadLine($sav, 5)) Local $bMasterPasswordHash=(FileReadLine($sav, 6)) Local $sPassword="" While $sPassword = "" $sPassword=_GetPassword() WEnd 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 Func _GetPassword() $hPasswordGetter = GUICreate("LogIn", 200, 100, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION), $WS_EX_TOPMOST) $hPG_Label = GUICtrlCreateLabel("Enter Password"&(FileReadLine($sav, 5)), 10, 5, 180, 20) $hPG_Input = GUICtrlCreateInput("", 10, 30, 180, 20, $ES_PASSWORD) $hPG_Button = GUICtrlCreateButton("Enter", 100, 60, 80, 30) GUICtrlSetOnEvent(-1, "_PG_Button") GUISetState() Local $aPos = WinGetPos($hPasswordGetter) _MouseTrap($aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3]) Local $sPassword = "" $fPassword_Ready = False While $sPassword = "" While $fPassword_Ready = False Sleep(10) WEnd $fPassword_Ready = False Local $sPassword = GUICtrlRead($hPG_Input) WEnd GUIDelete($hPasswordGetter) _MouseTrap() Return $sPassword EndFunc Func _PG_Button() $fPassword_Ready = True EndFuncYou will also need to add this line at the top of your script:Global $fPassword_Ready = FalseM23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
Thudo Posted September 3, 2010 Author Posted September 3, 2010 Most wonderful Melba.. I'll experiment with it then let you know. You are indeed a gem!
Thudo Posted September 7, 2010 Author Posted September 7, 2010 (edited) Ok I've cleaned up the GUI so it looks the form. Its working much better now that MouseTrap detects the GUI box. Here is the updated code:expandcollapse popupGlobal $fPassword_Ready = False Func _PasswordCheck() Local $iXTimes = 5, $iCount = 1 While 1 Local $bPasswordHash=(FileReadLine($sav, 5)) Local $bMasterPasswordHash=(FileReadLine($sav, 6)) Local $sPassword= "" While $sPassword = "" $sPassword=_GetPassword() WEnd If _Crypt_HashData($sPassword,$CALG_MD5)=$bPasswordHash or _Crypt_HashData($sPassword,$CALG_MD5)=$bMasterPasswordHash Then Return $sPassword Select Case $sPassword = "" Return 0 _ScreenSaverReturn() 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 contact help desk 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 Func _GetPassword() $hPasswordGetter = GUICreate('Login', 330, 85, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION), $WS_EX_TOPMOST) $hPG_Label = GUICtrlCreateGroup('Enter Password '&(FileReadLine($sav, 5)), 4, 10, 323, 40) $hPG_Input = GUICtrlCreateInput("", 10, 25, 310, 20, $ES_PASSWORD) $hPG_Button = GUICtrlCreateButton('OK', 100, 55, 50, 20) GUICtrlSetOnEvent(-1, "_PG_Button") $hCL_Button =GUICtrlCreateButton('Cancel', 185, 55, 50, 20) GUICtrlSetOnEvent(-1, "_ScreenSaverReturn") GUISetState() Local $aPos = WinGetPos($hPasswordGetter) ;~ _MouseTrap($aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3]) Local $sPassword = "" $fPassword_Ready = False While $sPassword = "" While $fPassword_Ready = False Sleep(10) WEnd $fPassword_Ready = False Local $sPassword = GUICtrlRead($hPG_Input) WEnd GUIDelete($hPasswordGetter) ;~ _MouseTrap() Return $sPassword EndFunc Func _PG_Button() $fPassword_Ready = True EndFunc Func _ScreenSaverReturn() _ScreenSaverHotKey() EndFunc ;==>_ScreenSaverReturnHere is what is left to figure out:1) $hPG_Input is not piping the user's input over to _PasswordCheck() to be checked if its valid or not. Not sure whats wrong here.2) Is it possible when the user hits the ESC key or the CANCEL button it can revert back to its pre-GUI state basically calling "_ScreenSaverReturn()" which then calls "_ScreenSaverHotKey()". It used to sort of do this back when I used the InputBox but not sure why it won't properly work with a GUI? It works for CANCEL (although see #3) but not for ESC.3) One thing I don't quite understand is when I hit the CANCEL button it runs "_ScreenSaverReturn" fine by reverting back to the screensaver. But when the Password GUI up there is re-called a second time, the CANCEL button doesn't invoke "_ScreenSaverReturn" -- it simply goes back to the Password GUI. Can it be set to keep looping back to "_ScreenSaverReturn" like it does the first time? Not sure why it works on the first CANCEL but not afterwards. Thanks so much Melba and everyone else who can assist.. I'm nearly there.. Edited September 7, 2010 by Thudo
Moderators Melba23 Posted September 7, 2010 Moderators Posted September 7, 2010 Thudo, The password gets passed back with no problem (when I have added all the extra lines needed to make your code snippet actually run ) - why do you think it is not? As for the other questions, you will need to post the whole script. I have a horrible feeling that you are running into recursion problems - that is calling functions from within functions. This would exlain why you do not end up where you think you should be - because you did not start from where you thought you started! M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
Thudo Posted September 7, 2010 Author Posted September 7, 2010 The password gets passed back with no problem (when I have added all the extra lines needed to make your code snippet actually run ) - why do you think it is not?Oddly, when I enter the right password nothing happens when I click OK. If the password is correct, its supposed to kill the Login GUI but right now it just flashes back to the Login GUI after clicking OK. Putting in a wrong password is supposed to bring up the "Invalid Password" warning box but just goes back to the Login GUI box. CANCEL and hitting the ESC key are supposed to kill the Login GUI and put it back to its original state but does nothing currently. As for the other questions, you will need to post the whole script. I have a horrible feeling that you are running into recursion problems - that is calling functions from within functions. This would explain why you do not end up where you think you should be - because you did not start from where you thought you started! Fer sure.. that will allow you to see the larger picture: Full code with explanation is actually posted right above in this post. Whats different is that _PasswordCheck() and _GetPassword() have been substituted with your coding facility so the older InputBox was omitted.Hope that helps..
Moderators Melba23 Posted September 7, 2010 Moderators Posted September 7, 2010 Thudo, First, I am not wasting my time integrating various bits of code together. Secondly, even if I did there is no guarantee that the resulting script would be the same as the one you are working on at the moment. So if you would like some help, please post the current complete version of the code you are having trouble with and which led you to post this afternoon. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
Thudo Posted September 7, 2010 Author Posted September 7, 2010 please post the current complete version of the code you are having trouble with and which led you to post this afternoon.Well I can forgo #3 and focus on #1 and #2 because those essentially worked with the older InputBox. So the current code I am having the most problems with is still the one I posted this afternoon here just above. If we can get by why that code is not reading the user's input and passing it to the MD5 hash then determine how to get CANCEL and ESC keys to kill the Login GUI then that's a big step. Do you want me to post the entire code with your changes or just tackling the Password GUI first? I want to be as accommodating as possible.
Moderators Melba23 Posted September 7, 2010 Moderators Posted September 7, 2010 Thudo,What part ofplease post the current complete version of the code you are having trouble withare you having trouble understanding?You include the whole code in your next post - I continue to help. You do not - I do not. Is that clear enough? M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
Thudo Posted September 7, 2010 Author Posted September 7, 2010 (edited) Thanks M.. here is the full code: expandcollapse popup#include <Crypt.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <Misc.au3> #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=ScreenSaver.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseAnsi=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** TraySetState(2) ; Disable the tray icon ; Determine cfg paths Local $TempDir=("") ; network path to cfg Local $TempDir2=("C:\") ; 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:\") ; where the images are stored FileWrite($sav, @CRLF & '15000') ; Time in ms between image transitions (standard is 15 seconds) FileWrite($sav, @CRLF & '.bmp|.jpg|.gif') ; Image formats supported FileWrite($sav, @CRLF & '60000') ; Time in ms between idle timeouts FileWrite($sav, @CRLF & "0x098F6BCD4621D373CADE4E832627B4F6") ; 'test' default Hash password to unlock screensaver (in MD5 Encyption) FileWrite($sav, @CRLF & "0x6D662F965D1E85BB367EFAA03594C5A1") ; 'sdm' 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', 400, 150, -1, -1, BitOR(0x00040000, 0x00000080)) GUISetOnEvent(-3, '_PrefClose') GUICtrlCreateGroup('Pictures folder', 5, 5, 385, 42) $p_pic = GUICtrlCreateEdit(FileReadLine($sav, 1), 10, 20, 320, 20, 2048 + 128) GUICtrlCreateButton('Browse', 335, 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 (sec)', 170, 50, 110, 40) $tdisp = GUICtrlCreateEdit(FileReadLine($sav, 2)/1000, 195, 67, 60, 17, 8192 + 128) GUICtrlCreateGroup('Idle Timeout (mins)', 290, 50, 100, 40) $tidle = GUICtrlCreateEdit(FileReadLine($sav, 4)/1000/60, 310, 67, 60, 17, 8192 + 128) GUICtrlCreateButton('Apply', 140, 95, 80, 20) GUICtrlSetOnEvent(-1, '_PrefApply') GUISetState(@SW_HIDE, $PGUI) #EndRegion Pref GUI If @Compiled or NOT @Compiled Then ; Run ScreenSaver regardless _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)*1000 & @CRLF) If (GUICtrlRead($tdisp) = '') 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|') If (GUICtrlRead($tidle) <> '') Then FileWrite($sav, @CRLF & GUICtrlRead($tidle)*1000*60) If (GUICtrlRead($tidle) = '') Then FileWrite($sav, @CRLF & '2000') FileWrite($sav, @CRLF & "0x098F6BCD4621D373CADE4E832627B4F6") ; 'test' default Hash password to unlock screensaver (in MD5 Encyption) FileWrite($sav, @CRLF & "0x6D662F965D1E85BB367EFAA03594C5A1") ; 'sdm' master unchanging Hash password to unlock screensaver for support teams (in MD5 Encyption) Return Call('_PrefClose') EndFunc ;==>_PrefApply Func _PrefOpen() GUICtrlSetData($p_pic, FileReadLine($sav, 1)) GUICtrlSetData($tdisp, FileReadLine($sav, 2)/1000) $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 ; Initiates password facility Func _AskPassword() _StopScreenSaver() _PasswordCheck() EndFunc Func _StopScreenSaver() $bl_ScreenSaver = False GUIDelete($CGUI) GUIDelete($GUI) _WinAPI_ShowCursor(1) EndFunc Global $fPassword_Ready = False Func _PasswordCheck() Local $iXTimes = 5, $iCount = 1 While 1 Local $bPasswordHash=(FileReadLine($sav, 5)) Local $bMasterPasswordHash=(FileReadLine($sav, 6)) Local $sPassword= "" While $sPassword = "" $sPassword=_GetPassword() WEnd If _Crypt_HashData($sPassword,$CALG_MD5)=$bPasswordHash or _Crypt_HashData($sPassword,$CALG_MD5)=$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 contact your local Associate or Front Store Manager 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 Func _GetPassword() $hPasswordGetter = GUICreate('Login', 330, 85, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION), $WS_EX_TOPMOST) $hPG_Label = GUICtrlCreateGroup('Enter Password '&(FileReadLine($sav, 5)), 4, 10, 323, 40) $hPG_Input = GUICtrlCreateInput("", 10, 25, 310, 20, $ES_PASSWORD) $hPG_Button = GUICtrlCreateButton('OK', 100, 55, 50, 20) GUICtrlSetOnEvent(-1, "_PG_Button") $hCL_Button =GUICtrlCreateButton('Cancel', 185, 55, 50, 20) GUICtrlSetOnEvent(-1, "_ScreenSaverReturn") GUISetState() Local $aPos = WinGetPos($hPasswordGetter) ;~ _MouseTrap($aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3]) ; -- disabled for testing purposes Local $sPassword = "" $fPassword_Ready = False While $sPassword = "" While $fPassword_Ready = False Sleep(10) WEnd $fPassword_Ready = False Local $sPassword = GUICtrlRead($hPG_Input) WEnd GUIDelete($hPasswordGetter) ;~ _MouseTrap() ; -- disabled for testing purposes Return $sPassword EndFunc Func _PG_Button() $fPassword_Ready = True EndFunc Func _ScreenSaverReturn() _ScreenSaverHotKey() 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) GUISetBkColor(0x000000, $GUI) GUISetState(@SW_SHOW, $GUI) WinSetOnTop($GUI, "", 1) EndIf Global $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 $check = FileFindFirstFile($s_path & '*.*') If $check = -1 Then Exit ConsoleWrite('!> FileFindFirstFile' & Chr(13)) While $bl_ScreenSaver = True 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 _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 be random) Func __SetPicture($hGUI, $ID, $p_path, $idisp, $hwnd) GUICtrlSetImage($ID, $p_path) _WinAnimate($hGUI, Random(1, 10, 1), 1, 700) $Init = TimerInit() While 1 Sleep(300) If ($hwnd = 'Screen Saver') Then 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) 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) EndFunc ;==>_IdleTicks ; This part disabled as doesn't work as expected. Above _IdleTicks used for testing purposes. ; ----------------------------------------------- ;~ 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 For testing purposes.. put this in C:\ drive and name it screensaver.cfg. Otherwise, the above code will assume its not there and create one for you. C:\ 5000 .bmp|.jpg|.gif 60000 0x136E264E94E5BE49096C7A54F33646B8 0x6D662F965D1E85BB367EFAA03594C5A1Password is "test". You can throw a single .bmp or .gif or .jpg file in C:\ to see the test or leave no image files and screen will be dark where images would be displayed. Edited September 8, 2010 by Thudo
Moderators Melba23 Posted September 7, 2010 Moderators Posted September 7, 2010 Thudo,This could take a while..... Fortunately for you the weather forecast says it will to be too wet for golf tomorrow, so I MIGHT find some time to look over this "spaghetti". Good night! M23P.S. Are you actually thinking of using this as a security measure for your entire company system?  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
Thudo Posted September 7, 2010 Author Posted September 7, 2010 Fortunately for you the weather forecast says it will to be too wet for golf tomorrow, so I MIGHT find some time to look over this "spaghetti"hehe.. it actually works quite well so its more linguine then even angel-haired spaghettini Are you actually thinking of using this as a security measure for your entire company system?Yep.. this is what was decreed for now as the systems this is being applied on will not have Windows Authentication via AD enabled. Its all profile-based so as a stop-gap measure we have this simulating what we've all taken for granted in Windows since the mid-90s. This works, in principle, but this is easier to do then the incredible task of giving thousands of machines AD logins. Thats why getting this working is really crucial at this point. Yer an absolute life-saver, melba.. beyond the call!
Moderators Melba23 Posted September 8, 2010 Moderators Posted September 8, 2010 Thudo, it actually works quite wellWell, you could have fooled me! That was one of the most tortuous debugs I think I have ever done. I cannot begin to list the things I found which were not working, but there are a few to be going on with: - The FileFindFirst/NextFile code was not correct. - The RegExpReplace you were using to get the ext did not produce the .ext format with which you were comparing it. As a result the image paths being passed to various functions were all over the place and so I have no idea how you ever got an image to display. - I have no idea what some of the code was trying to do - for example, there was one section which started: If @Compiled Or Not @Compiled Then ; But this will always be true as you accept either of the 2 possible options! ; Code Else ; Code which would never, ever be executed Or what all the Process code is about. You might try to comment sometimes - if you have the slightest idea what the code does, of course. And I was absolutely correct about the recursion - you were recalling functions all the time without returning to the main loop. Had you tried running this for any length of time it would have crashed badly. This is one of the major errors when people start coding in OnEvent mode. Oh, and the password function was failing because you had a necessary Global declaration hidden among the functions where it was never seen or actioned. I have completely rewritten the script in GetMessage mode and I believe it now works more or less as you want it: expandcollapse popup#include <Crypt.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <Misc.au3> #include <WinAPI.au3> #include <Timers.au3> Global $sav, $sPath, $lticks, $GUI, $CGUI, $PGUI, $PIC, $bl_ScreenSaver = False, $w = @DesktopWidth, $h = @DesktopHeight Global $parent_PID = "", $hWnd = "" Global $bmp = False, $jpg = False, $gif = False Global $s_path, $n_disp ; Determine cfg paths Global $TempDir = ("") ; network path to cfg Global $TempDir2 = ("C:\") ; local path to cfg (used as backup) #cs ; Ensure network path is always backed-up to local path. If FileExists($TempDir) Then FileCopy($TempDir, $TempDir2, 1) EndIf #ce ; Choose alternate path if primary does not exist If FileExists($TempDir) Then $sav = $TempDir & '\ScreenSaver.cfg' Else $sav = $TempDir2 & '\ScreenSaver.cfg' EndIf $sPath = FileReadLine($sav, 1) #cs #Region Check cfg If Not FileExists($sav) Then FileWrite($sav, "C:\") ; where the images are stored FileWrite($sav, @CRLF & '15000') ; Time in ms between image transitions (standard is 15 seconds) FileWrite($sav, @CRLF & '.bmp|.jpg|.gif') ; Image formats supported FileWrite($sav, @CRLF & '60000') ; Time in ms between idle timeouts FileWrite($sav, @CRLF & "0x098F6BCD4621D373CADE4E832627B4F6") ; 'test' default Hash password to unlock screensaver (in MD5 Encyption) FileWrite($sav, @CRLF & "0x6D662F965D1E85BB367EFAA03594C5A1") ; 'sdm' master unchanging Hash password to unlock screensaver for support teams (in MD5 Encyption) EndIf #EndRegion Check cfg #ce #Region Pref Create $PGUI = GUICreate('Picture Screen Saver', 350, 150, -1, -1, BitOR(0x00040000, 0x00000080)) GUICtrlCreateGroup('Pictures folder', 5, 5, 335, 42) $p_pic = GUICtrlCreateEdit(FileReadLine($sav, 1), 10, 20, 270, 20, 2048 + 128) $hPGUI_Browse = GUICtrlCreateButton('Browse', 285, 20, 50, 20) 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) GUICtrlCreateGroup('Idle timeout', 260, 50, 80, 40) $tidle = GUICtrlCreateEdit(FileReadLine($sav, 4), 270, 67, 60, 17, 8192 + 128) $hPGUI_Apply = GUICtrlCreateButton('Apply', 140, 95, 80, 20) GUISetState(@SW_HIDE, $PGUI) #EndRegion Pref Create If Not FileExists($sav) Then ; Check for command line If Not $CmdLine[0] Then ConsoleWrite('!> $CmdLine[0]' & @CRLF) ; Exit if no CmdLine Exit ElseIf StringInStr($CmdLine[1], '/p') Then If $CmdLine[0] < 2 Then MsgBox(48, 'Picture scr', 'Invalid preview window information supplied.') Exit Else $parent_PID = _ProcessGetParent(@AutoItPID) $w = 152 $h = 112 $hWnd = HWnd($CmdLine[2]) EndIf ElseIf Not StringInStr($CmdLine[1], '/s') Then _PrefOpen() EndIf EndIf $s_path = FileReadLine($sav, 1) $n_disp = FileReadLine($sav, 2) $Poss_Ext = FileReadLine($sav, 3) $i_WaitIdleTime = FileReadLine($sav, 4) $check = FileFindFirstFile($s_path & '*.*') If $check = -1 Then ConsoleWrite('!> FileFindFirstFile' & Chr(13)) Exit EndIf While 1 $sNext = FileFindNextFile($check) If @error Then ; No valid files $sNext = "" ExitLoop EndIf If StringInStr($sNext, ".") Then $s_Ext = StringRegExpReplace($sNext, "^.*\.", ".$1") If StringRegExp($s_Ext, "(?i)" & $Poss_Ext) Then ExitLoop EndIf WEnd ;_WinAPI_ShowCursor(0) _ScreenSaverPicture($w, $h, $hWnd) If ($s_Ext = '.bmp') And $bmp = True Then __SetPicture($CGUI, $PIC, $s_path & $sNext) ElseIf ($s_Ext = '.jpg') And $jpg = True Then __SetPicture($CGUI, $PIC, $s_path & $sNext) ElseIf ($s_Ext = '.gif') And $gif = True Then __SetPicture($CGUI, $PIC, $s_path & $sNext) EndIf $iBegin = TimerInit() Sleep(500) ; Allow settle time from start click While 1 Sleep(10) Switch $bl_ScreenSaver Case True ; Has user actioned something in the last 500 ms If _Timer_GetIdleTime() < 500 Then Switch _AskPassword() ; Password good Case 1 ; What now? $bl_ScreenSaver = False ; Could combine the next 2 if you wish them to do the same thing <<<<<<<<<<<<<<<<<<<<< ; Cancel pressed Case 0 ; restart screensaver ;_WinAPI_ShowCursor(0) _ScreenSaverPicture($w, $h, $hWnd) ; Password fail x 5 Case -1 ; Restart screensaver ;_WinAPI_ShowCursor(0) _ScreenSaverPicture($w, $h, $hWnd) EndSwitch EndIf Case False If _Timer_GetIdleTime() > $i_WaitIdleTime Then ;_WinAPI_ShowCursor(0) _ScreenSaverPicture($w, $h, $hWnd) EndIf EndSwitch If TimerDiff($iBegin) > $n_disp Then While 1 $sNext = FileFindNextFile($check) If @error Then ; No valid files FileClose($check) $check = FileFindFirstFile($s_path & '*.*') ; Go back to the first file $sNext = FileFindNextFile($check) EndIf If StringInStr($sNext, ".") Then $s_Ext = StringRegExpReplace($sNext, "^.*\.", ".$1") If StringRegExp($s_Ext, "(?i)" & $Poss_Ext) Then ExitLoop EndIf WEnd If $parent_PID <> "" Then $child_PID = _ProcessGetChildren($parent_PID) If $child_PID[0] > 1 Then Exit ;Another ss selected If Not WinExists($CmdLine[2]) Then Exit EndIf If ($s_Ext = '.bmp') And $bmp = True Then __SetPicture($CGUI, $PIC, $s_path & $sNext) ElseIf ($s_Ext = '.jpg') And $jpg = True Then __SetPicture($CGUI, $PIC, $s_path & $sNext) ElseIf ($s_Ext = '.gif') And $gif = True Then __SetPicture($CGUI, $PIC, $s_path & $sNext) EndIf $iBegin = TimerInit() EndIf WEnd #Region Pref Create 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) While 1 Switch GUIGetMsg() Case $hPGUI_Browse $path = FileSelectFolder('Select picture folder', @MyDocumentsDir, 1 + 2) If @error Then ConsoleWrite('!> FileSelectFolder' & @CRLF) Exit EndIf GUICtrlSetData($p_pic, $path & '\') Case $hPGUI_Apply FileDelete($sav) FileWrite($sav, GUICtrlRead($p_pic)) If (GUICtrlRead($tdisp) <> '') Then FileWrite($sav, @CRLF & GUICtrlRead($tdisp) & @CRLF) Else FileWrite($sav, @CRLF & '2000' & @CRLF) EndIf If (GUICtrlRead($tidle) <> '') Then FileWrite($sav, @CRLF & GUICtrlRead($tidle) & @CRLF) Else FileWrite($sav, @CRLF & '2000' & @CRLF) EndIf If (GUICtrlRead($bmp) = 1) Then FileWrite($sav, '.bmp|') If (GUICtrlRead($jpg) = 1) Then FileWrite($sav, '.jpg|') If (GUICtrlRead($gif) = 1) Then FileWrite($sav, '.gif|') GUISetState(@SW_HIDE, $PGUI) $bl_ScreenSaver = True EndSwitch WEnd EndFunc ;==>_PrefOpen #EndRegion Pref Create #Region ScreensaverPic ; _ScreenSaverPicture Func _ScreenSaverPicture($width, $height, $hWnd = 'Screen Saver') $bl_ScreenSaver = True Local $s_path = FileReadLine($sav, 1) Local $n_disp = FileReadLine($sav, 2) If ($hWnd = 'Screen Saver') Then $GUI = GUICreate('Screen Saver', @DesktopWidth, @DesktopHeight, 0, 0, 0x80000000) GUISetBkColor(0x000000, $GUI) GUISetState(@SW_SHOW, $GUI) WinSetOnTop($GUI, "", 1) EndIf $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) $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 Sleep(500) EndFunc ;==>_ScreenSaverPicture Func __SetPicture($hGUI, $ID, $p_path) _WinAnimate($hGUI, Random(1, 10, 1), 2, 700) GUICtrlSetImage($ID, $p_path) _WinAnimate($hGUI, Random(1, 10, 1), 1, 700) EndFunc ;==>__SetPicture #EndRegion ScreensaverPic #Region Password Func _AskPassword() ; Stop screensaver $bl_ScreenSaver = False GUIDelete($CGUI) GUIDelete($GUI) _WinAPI_ShowCursor(1) Local $bPasswordHash = (FileReadLine($sav, 5)) Local $bMasterPasswordHash = (FileReadLine($sav, 6)) Local $iXTimes = 5, $iCount = 0 Local $sPassword = "" $hPasswordGetter = GUICreate('Login', 330, 85, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION), $WS_EX_TOPMOST) $hPG_Label = GUICtrlCreateGroup('Enter Password ' & (FileReadLine($sav, 5)), 4, 10, 323, 40) $hPG_Input = GUICtrlCreateInput("", 10, 25, 310, 20, $ES_PASSWORD) GUICtrlSetState($hPG_Input, $GUI_FOCUS) $hPG_OK = GUICtrlCreateButton('OK', 100, 55, 50, 20) $hPG_Cancel = GUICtrlCreateButton('Cancel', 185, 55, 50, 20) GUISetState() While 1 Switch GUIGetMsg() Case $hPG_OK GUISetState(@SW_HIDE, $hPasswordGetter) $iCount += 1 If $iCount = $iXTimes Then ;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 contact your local Associate or Front Store Manager for Assistance..") GUIDelete(GUISetState(@SW_HIDE, $hPasswordGetter)) Return -1 EndIf $sAttempt = GUICtrlRead($hPG_Input) If _Crypt_HashData($sAttempt, $CALG_MD5) = $bPasswordHash Or _Crypt_HashData($sAttempt, $CALG_MD5) = $bMasterPasswordHash Then Return 1 MsgBox(16, "Access Denied", "Password Incorrect!" & @CR & "You have " & $iXTimes - $iCount & " trys left") GUICtrlSetData($hPG_Input, "") GUICtrlSetState($hPG_Input, $GUI_FOCUS) GUISetState(@SW_SHOW, $hPasswordGetter) Case $hPG_Cancel GUIDelete(GUISetState(@SW_HIDE, $hPasswordGetter)) Return 0 EndSwitch WEnd EndFunc ;==>_AskPassword #EndRegion Password #Region Process functions ; _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 #EndRegion Process functions #Region 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 #EndRegion WinAnimate However, to be quite frank, I firmly believe that you are in way over your head and if you really think that this will provide any security at all against anyone other than a complete novice, then you are seriously deluding yourself. Furthermore, it has taken you 2 months to get as far as producing that abomination of a script. Had you put in any effort at all into reading the Help file yourself, you would not have made many of the glaringly obvious errors that you did. I can only assume that you are simply seeking others to actually write the script for you by producing complete garbage and then hoping that various kind souls here will actually produce something that works. Enough. You are on your own now as far as I am concerned - I am not wasting any more of my time on this. It was only the weather keeping me from the golf course and my own personal refusal to be beaten by the problem that made me stick around long enough to produce the above. And finally I repeat my warning - this is not and never will be secure! "click" M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
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