TPlanet Posted November 20, 2008 Share Posted November 20, 2008 Hi all, I wrote this to limit my children to use the pc to an hour per day. Every day it goes back to 60 minutes and we can stop it or adding 30 minutes from the icon on the tray(with a password, of course). I would like the script to pause (or to stop the timer) while the session is not active. I mean if they change user instead of loging off. So, here is the code... Enjoy; CODE #NoTrayIcon #include <GUIConstantsEx.au3> #include <EditConstants.au3> #Include <Constants.au3> Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. Global $TmpRestant, $RegMotDePasse $Jour = @MDAY $RegPath = "hkcu\software\timer" $RegMotDePasse = RegRead("hklm\software\timer","MotDePasse") If @error Then $RegMotDePasse = "password" ;if no set password in the registry, we set "password" as password $RegTmpMax = RegRead("hklm\software\timer","TempMax") If @error Then $RegTmpMax = 60 ;if no set max time in the registry, we set 60 minutes $TmpMax = (60*$RegTmpMax) $RegJour = RegRead($RegPath, "jour") ; if not yet connected today, we set the timer back to max time If @error or $RegJour <> $Jour then $TmpRestant = $TmpMax ;en secondes RegWrite($RegPath, "jour", "reg_sz", $Jour) RegWrite($RegPath, "tempsrestant", "reg_sz", $TmpRestant) Else $TmpRestant = (RegRead($RegPath, "tempsrestant")+15) ;add 15 seconds to signon on process If $TmpRestant <= 30 Then _finsession() ;if already timed out... bye bye EndIf ;~ tray to add 30 minutes or to stop the script $FermeTimer = TrayCreateItem("Illimité") TrayCreateItem("") $Ajout30Min = TrayCreateItem("Ajout 30 Min") TraySetState() ;~ Début du compte à rebours $begin = TimerInit() While 1 $dif = TimerDiff($begin) $SecRest = ($TmpRestant - (Round($dif/1000,0))) $MinRest = (Ceiling($SecRest/60)) ToolTip("Reste " & $MinRest & " Min.", 450, 1, "") RegWrite($RegPath, "tempsrestant", "reg_sz", $SecRest) If $SecRest <= 0 Then ExitLoop $msg = TrayGetMsg() ;verifie si on a activé une commande du tray Select Case $msg = 0 Case $msg = $FermeTimer _Verif("Exit") Case $msg = $Ajout30Min _Verif("30min") EndSelect sleep(100) WEnd _finsession() ;on appelle la fonction de fermeture de session Exit ;~ *********************************** ;~ Fonctions ;~ *********************************** Func _Verif($action) Local $btn, $MotDePasse, $msg, $reponse GUICreate("Mot de passe", 100, 60, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, $WS_CAPTION, 0x00000018) $MotDePasse = GUICtrlCreateInput("", 10, 5, 125, 20 ,$ES_PASSWORD) $btn = GUICtrlCreateButton("Ok", 40, 30, 60, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btn ExitLoop Case $msg = $MotDePasse ExitLoop EndSelect WEnd if GUICtrlRead($MotDePasse) = $RegMotDePasse Then GUIDelete() Select Case $action = "Exit" Exit Case $action = "30min" $TmpRestant = ($TmpRestant + 1800) EndSelect Else GUIDelete() MsgBox(0,"Erreur", "Mauvais mot de passe",3) EndIf EndFunc ;_Verif func _finsession() For $Compteur = 1 to 60 ToolTip("La session va se fermer dans " & (61-$Compteur) & " secondes... c'est le temps de sauvergarder!", 450, 450, "Temps écoulé") Sleep(1000) Next Shutdown(4) EndFunc ;_finsession Thanks, Thierry Link to comment Share on other sites More sharing options...
herewasplato Posted November 21, 2008 Share Posted November 21, 2008 (edited) You would probably need to change to a different type of timer function and check for the presence of the desktop to determine if the user is logged on or if fast user switching has been used. something like: for $i = 60 to 1 step -1 if not WinExists("Program Manager") then _pause_timer() sleep(1000 * 60) next func _pause_timer() do sleep(999) until WinExists("Program Manager") endfunc I'm really not sure if that code will work and I like to test such things before I post - but I do not have fast user switching enabled on this computer. Maybe others online can comment. BTW, good for you for setting limits for kids online. Edited November 21, 2008 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
matwachich Posted February 5, 2011 Share Posted February 5, 2011 I was searching for exactly the same thing, and exatly for the same reason (but it's not my soon, but brother!) I tried the methode but it's not working, cause even if we lock the session, the Program Manager Window (the desktop) is always existing. Link to comment Share on other sites More sharing options...
ChrisL Posted February 5, 2011 Share Posted February 5, 2011 How about checking @userName, store the userName, Date and Timer Values in the regitry. [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
matwachich Posted February 5, 2011 Share Posted February 5, 2011 http://msdn.microsoft.com/en-us/library/aa383828.aspx Link to comment Share on other sites More sharing options...
matwachich Posted February 5, 2011 Share Posted February 5, 2011 Link to comment Share on other sites More sharing options...
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