Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Timer no longer working


  • Please log in to reply
1 reply to this topic

#1 JonCross

JonCross

    Wayfarer

  • Active Members
  • Pip
  • 50 posts

Posted 15 February 2010 - 09:02 PM

Hello everyone, I run a computer lab at an elementary school and I have been working on a computer lab automation script. Bellow is a portion of the script that runs on the computers. I added the ability to run some commands via the tray icon but now that I have done that the idle timer will not work any ideas?

Here is the code (its kinda long):
AutoIt         
#NoTrayIcon #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <Misc.au3> #include <Timers.au3> #include <string.au3> #include <ChangeResolution.au3> #include <zip.au3> if _Singleton("Daemon",1) = 0 Then     Msgbox(0,"Warning","An occurence of Control Daemon is already running.", 10)     Exit EndIf Opt("TrayMenuMode",1) Global $Server = "\\adm-24-server01\RCData\ComputerAutomation" Global $Local ="C:\HighlandAutomation" Global $iIdleTime $Refresh  = TrayCreateItem("Refresh Computer", -1, 0) $teacher = TrayCreateItem("Teacher Mode", -1, 1) $close = TrayCreateItem("Exit", -1, 9) $admin = TrayCreateItem("Admin Mode", -1, 2) TraySetState() While 1     $iIdleTime = _Timer_GetIdleTime()       IF FileExists("C:\thinclient") Then         Exit     ElseIf $iIdleTime > 300000 Then ;#5 Mintue Idle Timer         Ping ("adm-24-server01")         If @error Then         _Offline()         endif     ElseIf $iIdleTime > 1800000 Then ;#30 Minute Idle time         DesktopRefresh()     Elseif not ProcessExists("Rules.exe") AND $iIdleTime > 600000 Then ;#10 Minute Idle time         Run($Local&"\Rules.exe")     ElseIF FileExists($Server&"\shutdown")Then         shutdown (8)     ElseIF FileExists($Server&"\logoff")Then         Shutdown (0)     ElseIF FileExists($Server&"\reboot")Then         Shutdown (2)     ElseIF FileExists($Server&"\nonet")Then         ProcessClose("IExplore.exe")     ElseIF FileExists($Server&"\xattack") Then         ProcessClose("TimezAttackLauncher.exe")         ProcessClose("BigBrainz_TimezAttackWin.exe")     ElseIf FileExists($Server&"\mute") Then         Send("{VOLUME_MUTE}")         Sleep(100)     ElseIf FileExists($Server&"\attentionON")Then         _Attention()            ElseIf FileExists($Server&"\messageON")Then         _Message()     ElseIf FileExists($Server&"\TakeAttendance")Then         _Attendance()     ElseIf FileExists($Server&"\refresh") Then         DesktopRefresh()         Sleep(10000)     EndIf     $msg = TrayGetMsg() Select     Case $msg  = 0         ContinueLoop     Case $msg = $refresh         DesktopRefresh()     Case $msg = $close         close()     Case $msg = $teacher         Teacher()     Case $msg = $admin         Controler()     EndSelect WEnd Func Close()     $var = IniReadSection($Server&"\settings.ini", "exit") If @error Then     MsgBox(4096, "", "Error occurred.") Else     For $i = 1 To $var[0][0]     $password = $var[$i][1]     $decript = _HexToString($password) Next        $passwd = InputBox("Security Check", "Enter Exit password.", "", "*", 190, 115,-1,-1, 5) IF $passwd = $decript then       Exit Else     MsgBox(48, "Wrong Password", "Sorry, that was not the correct Password!",3) EndIf EndIf EndFunc Func Teacher() $var = IniReadSection($Server&"\settings.ini", "teacher") If @error Then     MsgBox(4096, "", "Error occurred.") Else     For $i = 1 To $var[0][0]     $password = $var[$i][1]     $decript = _HexToString($password) Next        $passwd = InputBox("Security Check", "Enter Teacher password.", "", "*", 190, 115,-1,-1,5) IF $passwd = $decript then       TeacherMode() Else     MsgBox(48, "Wrong Password", "Sorry, that was not the correct Password!",3) EndIf EndIf EndFunc Func _Offline()     TraySetState()     TrayTip("SERVER OFFLINE!", "THE SERVER IS OFFLINE!", 30, 3)     While 1     $msg = Ping ("adm-24-server01")     Select         Case $msg = @Error             TrayTip("SERVER OFFLINE!", "THE SERVER IS OFFLINE!", 30, 3)             ContinueLoop         Case $msg > 1             ExitLoop         EndSelect     WEnd     Autoitsetoption("TrayIconHide", 1) EndFunc Func TeacherMode()     $Exit = TrayCreateItem("Exit Teacher Mode", -1, 1)     TrayItemDelete($Teacher)     TraySetState()     TrayTip("Teacher Mode", "This Computer is in Teacher Mode. Click HERE when Done.", 30, 1)     While 1     $msg = TrayGetMsg()     Select         Case $msg = 0             ContinueLoop         Case $msg = $exit             ExitLoop         EndSelect     WEnd     TrayItemDelete($Exit)     $teacher = TrayCreateItem("Teacher Mode", -1, 1) EndFunc Func _Attention()     $var1 = IniReadSection($Server&"\settings.ini", "attention") If @error Then     MsgBox(4096, "", "Error occurred.") Else     For $i = 1 To $var1[0][0]     $color = $var1[$i][1] Next BlockInput(1) GUICreate("Attention", @DesktopWidth + 10, @DesktopHeight +35, -1, -1, -1, $WS_EX_TOPMOST) GUISetBkColor($color) GUISetState(@SW_SHOW) While 1 If FileExists($Server&"\attentionOFF") Then ExitLoop     WEnd     GUIDelete()     BlockInput(0)     Send("{CTRLDown}", 0)     sleep(1000)     Send("{CTRLUP}", 0)     EndIf EndFunc Func _Attendance()     Local $Name     $Name = Inputbox("Attendance", "Enter Your First and Last Name","","","","",-1,-1,60)     WinSetOnTop("Attendance","",1)     FileWriteLine($Server&"\Attendance.txt", $Name)     FileClose($Server&"\Attendance.txt")     MsgBox(0, "Thank You", "Thank You", 10) EndFunc Func _Message() $var2 = IniReadSection($Server&"\settings.ini", "message") If @error Then     MsgBox(4096, "", "Error occurred.") Else     For $i = 1 To $var2[0][0]     $message = $var2[$i][1] Next     GUICreate("Attention", 355, 125, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)     GUISetFont(10, 400)     GUICtrlCreateedit($Message, 1, 1, 325,115, $ES_READONLY, $WS_EX_TRANSPARENT )     GUISetState()     While 1 If FileExists($Server&"\messageOFF") Then     ExitLoop     Endif     WEnd     GUIDelete()     EndIf EndFunc Func Controler()     Run($Server&"\Lab Controler.exe")     Sleep(3000)     WinWaitclose("Security Check")     TrayItemDelete($admin)     TraySetState()     WinwaitClose ("Computer Lab Controler")     $Admin = TrayCreateItem("Admin Mode", -1, 2) EndFunc Func DesktopRefresh() BlockInput(1) ;#Change Screen Res $iWidth = 1024 $iHeight = 768 $iBitsPP = 32 $iRefreshRate = 60 $vRes = _ChangeScreenRes($iWidth, $iHeight, $iBitsPP, $iRefreshRate) If @error Then MsgBox(262160, "ERROR", "Unable to change screen - check parameters") EndIf ;#End Change Screen SplashImageOn("Welcome to Highland Elementary School", $Local&"\splash.bmp");Splash Screen durring scrip run time ;Deletes all icons on the local accound desktop. FileDelete(@DesktopDir &"\*.*") ;Office Icons are created in only Office Version 2002, 2003 and 2007. IF FileExists("C:\Program Files\Microsoft Office\Office11\WinWord.exe") Then FileCreateShortcut("C:\Program Files\Microsoft Office\Office11\WinWord.exe", @Desktopdir & "\Word","C:\Program Files\Microsoft Office\Office11","","","C:\Program Files\Microsoft Office\Office11\WinWord.exe") FileCreateShortcut("C:\Program Files\Microsoft Office\Office11\PowerPNT.exe", @Desktopdir & "\Power Point","C:\Program Files\Microsoft Office\Office11","","","C:\Program Files\Microsoft Office\Office11\PowerPNT.exe") Elseif FileExists("C:\Program Files\Microsoft Office\Office10\WinWord.exe") Then FileCreateShortcut("C:\Program Files\Microsoft Office\Office10\WinWord.exe", @Desktopdir & "\Word","C:\Program Files\Microsoft Office\Office10","","","C:\Program Files\Microsoft Office\Office10\WinWord.exe") FileCreateShortcut("C:\Program Files\Microsoft Office\Office10\PowerPNT.exe", @Desktopdir & "\Power Point","C:\Program Files\Microsoft Office\Office10","","","C:\Program Files\Microsoft Office\Office10\PowerPNT.exe") Elseif FileExists("C:\Program Files\Microsoft Office\Office12\WinWord.exe") Then FileCreateShortcut("C:\Program Files\Microsoft Office\Office12\WinWord.exe", @Desktopdir & "\Word","C:\Program Files\Microsoft Office\Office12","","","C:\Program Files\Microsoft Office\Office12\WinWord.exe") FileCreateShortcut("C:\Program Files\Microsoft Office\Office12\PowerPNT.exe", @Desktopdir & "\Power Point","C:\Program Files\Microsoft Office\Office12","","","C:\Program Files\Microsoft Office\Office12\PowerPNT.exe") Else     EndIF ;Shortcuts will be created recreated _Zip_UnzipAll($Local&"\Desktop.zip", @DesktopDir, 1) ;Deletes temp Files and Misc Files FileDelete(@UserProfileDir&"\Cookies\*.txt") FileDelete(@UserProfileDir&"\Local Settings\Temporary Internet Files\*.*") FileDelete(@TempDir&"\*.*") FileDelete(@UserProfileDir&"\Recent\*.*") FileDelete(@FavoritesDir&"\*.*") FileDelete(@AppDataDir&"\Microsoft\Internet Explorer\Quick Launch\*.*") DirRemove(@FavoritesDir&"\Links", 1) DirRemove(@FavoritesDir&"\Favorites Bar", 1) ShellExecuteWait("RunDll32.exe"," InetCpl.cpl,ClearMyTracksByProcess 255") FileRecycleEmpty() ;Computer Lab Display Theme will be applied. Send("#m",0) ShellExecute($Local&"\Lab Theme.Theme") ControlFocus("Display Properties", "", "") WinwaitActive("Display Properties") Send("{ENTER}",0) WinWaitClose("Display Properties") ControlFocus("Program Manager", "", "") ;Desktop Icons Will be Auto Arragned Sleep (2000) MouseClick("Right", 920,25) Send("I") Send("A") BlockInput(0) Sleep(5000) Send("{LCTRL}", 0) SplashOff() ;RESTART Deamon FileDelete($local&"\Refresher.exe") FileCopy($server&"\Refresher.exe",$Local,1) Run($local&"\Refresher.exe",$local) Exit EndFunc

Edited by JonCross, 15 February 2010 - 09:17 PM.








#2 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,827 posts

Posted 16 February 2010 - 12:10 PM

JonCross,

As you have it set now, there are some major problems with the timer elements in your While...WEnd loop.

To start with, you are firing the timer events permanently once the trigger time has passed. For example, we reach the 5 minute point where you want to ping the server - it fires as we hit 5 minutes, but then also fires every pass through the loop from then on! :lol: Quite a lot of pings!

The next problem is the use of the If...ElseIf...EndIf structure. AutoIt only actions the first true condition on each pass. As you have the 5 minute case as the first option, AutoIt will always fire on that (once you have reached the required time as shown above) and so you will never test the subsequent 10 and 30 minute conditions. :(

To get over the timer problem, I would do something like this:
AutoIt         
$iCorr05 = 0 $iCorr10 = 0 $iCorr30 = 0 While 1     $iIdleTime = Int(_Timer_GetIdleTime() / 1000)     If $iIdleTime - $iCorr30 > 1800 Then ;#30 Minute Idle time         $iCorr30 = $iIdleTime         DesktopRefresh()     EndIf     If Not ProcessExists("Rules.exe") And $iIdleTime - $iCorr10 > 600 Then ;#10 Minute Idle time         $iCorr10 = $iIdleTime         Run($Local & "\Rules.exe")     EndIf     If $iIdleTime - $iCorr05 > 300 Then ;#5 Minute Idle Timer         $iCorr05 = $iIdleTime         Ping("adm-24-server01")         If @error Then             _Offline()         EndIf     EndIf

This way you test all of the delay times and only trigger the events at the required delay by effectively "resetting" the trigger time for each of them - I hope that it is clear from the code how that works. As I have introduced the 3 correction factors which augment each time you pass the respective idle delay, I have also reduced the size of the values they must hold by working in seconds rather than milliseconds so we do not bump up against AutoIt's maximum value limit(although I imagine that your system is never idle that long! :P ).

As I am not familiar with your system, I cannot say whether there is a similar problem lurking in the remainder if your If...ElseIf...EndIf structure, but if my assumption that each event is a unique occurrence and thus you are unlikely to have multiple files appearing simultaneously is correct, the structure seems robust as it is.

Quite why your timimg problems arrived when you added the tray menu is beyond me, but I hope the above helps resolve them. Please come back if it does not - or of you require any more help (not that you look as though you do!). :mellow:

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users