Is there anyone here with good autoit scripting knowledge? I have a screensaver I am working with which needs some things looked at. My main stumbling block is building a password facility to store passwords which can be configured and how to script the time it takes for the screensaver to wait so it considers its Idle thus turning on the screensaver.

Any help here would be appreciated, immensely!
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Might it be better to post the script? Yeah I have talked with people over @ AutoIT but everyone seems too busy. :(
Answered 07/13/2010 by: thudo
Senior Yellow Belt

Please log in to comment
0
Ok here is the script..

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

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

; 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 $w = @DesktopWidth, $h = @DesktopHeight, $sPath = FileReadLine($sav, 1)
Else
Local $sav = $TempDir & '\ScreenSaver.cfg', $lticks, $GUI, $CGUI, $bl_ScreenSaver = False
Local $w = @DesktopWidth, $h = @DesktopHeight, $sPath = FileReadLine($sav, 1)
endif
Opt('GUIOnEventMode', 1)

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

#Region Check cfg
If Not FileExists($sav) Then
FileWrite($sav, RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'My Pictures') & '\') ; Local store of cfg info
FileWrite($sav, @CRLF & '15000') ; Time in ms between image transitions
FileWrite($sav, @CRLF & '.bmp|.jpg|.gif') ; Image formats supported
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)

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

Func _AskPassword()
_StopScreenSaver()
MsgBox(64, "", "Enter Password")
EndFunc

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

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

If ($hwnd = 'Screen Saver') Then
Global $GUI = GUICreate('Screen Saver', @DesktopWidth, @DesktopHeight, 0, 0, 0x80000000)
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 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
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

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


Essentially what I want to do is the following:

1) Based on a setting in the screensaver.cfg, to determine inactivity to then enable the picture screensaver. Right now it assumes Windows will do it for the screensaver but our environment completely disables that. So I need another line in the cfg file to determine how long/idle time outs are handled.

2) Enable the screensaver using a HOTKEY combo (our WINDOWS keys are non-functional so we need other key combos) -- I think thats coded now as you'll note the hotkey code is now present. Any additional or recommended tweaks to that I would be open to.

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

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

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

Generally, adding in a password facility for the screensaver seems silly because Windows does that anyway but our environment does not use Active Directory to store security profiles -- we do it locally so anyone can log into Windows XP. The screensaver is meant as a layer of security hence why I need to code it. I'm mostly stuck on creating the password system and backdoor. Being new to AutoIT compounds my frustrating hence why I am reaching out as that screensaver is fantastic for what I need but need it slightly expanded upon.

Thanks Cserrins..

I will try and answer any outstanding questions you have regarding what I am trying to do here.

TuD.
Answered 07/13/2010 by: thudo
Senior Yellow Belt

Please log in to comment
0
Just following up.. you understand where I am going with the above?
Answered 07/14/2010 by: thudo
Senior Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity