AutoIt Forums: Shutdown/reboot/logoff Timer - AutoIt Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Shutdown/reboot/logoff Timer I know this may have been done thousands of times, but... Rate Topic: -----

#1 User is offline   Nahuel 

  • To Err is human, to Arr is pirate.
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,841
  • Joined: 25-June 07
  • Location:Argentina

Posted 10 August 2007 - 05:56 PM

Well... I wanted to share my timer with you guys. I find it pretty useful when I leave the computer on to download something and go to sleep or leave the house.

If you can check it out, tell me what you think :)

*updated*
I fixed some stuff that were wrong and causing extreme cpu usage and added a few functions to make it a bit better. (like, check if the user entered a valid time)
It also can display a personal message or reminder at the time you say.



Thanks to bogQ and Generator who gave me a hand with some important details.
Now, this program is perfect.

[ autoIt ]    ( ExpandCollapse - Popup )
#include <GuiConstants.au3> ;============================= ;Author: Nahuel Jose ;Language: AutoIT ;email:nahueljose@gmail.com ;============================= #include <GuiConstants.au3> $loop2=1 $AnchoVentana = 250 $AltoVentana = 200 $MargenIzquierdo=10 $MargenSuperior=10 $Separador=20 $AnchoEtiqueta=130 $AltoEtiqueta=22 Opt("TrayAutoPause",0) Opt("TrayMenuMode",1) GuiCreate("Timer", $AnchoVentana, $AltoVentana) ;Current time: $Reloj=GUICtrlCreateLabel(@HOUR&":"&@MIN,$AnchoVentana/2-$Separador,$MargenSuperior+6,$AnchoEtiqueta) GUICtrlSetFont($Reloj, 10, 500, "", "Verdana") ;Hour $HoraApagado = GUICtrlCreateInput (@HOUR,$MargenIzquierdo+5,$MargenSuperior+$Separador*2+10, 60, 20,$ES_READONLY) GUICtrlCreateUpdown($HoraApagado) GUICtrlSetLimit(-1, 23,00) GUICtrlSetLimit($HoraApagado, 2) GUICtrlCreateLabel("Hours",$MargenIzquierdo+5+65,$MargenSuperior+$Separador*2+12) ;Minutes $MinApagado = GUICtrlCreateInput (@MIN,$MargenIzquierdo+$Separador+100,$MargenSuperior+$Separador*2+10, 60, 20,$ES_READONLY) GUICtrlCreateUpdown($MinApagado) GUICtrlSetLimit(-1, 59,00) GUICtrlSetLimit($MinApagado, 2) GUICtrlCreateLabel("Minutes",$MargenIzquierdo+$Separador+100+65,$MargenSuperior+$Separador*2+12) ;Events $combo=GUICtrlCreateCombo("Shutdown",$MargenIzquierdo+5,$MargenSuperior+$Separador*4+25,220,200,$WS_VSCROLL+$CBS_DROPDOWNLIST+$CBS_AUTOHSCROLL) GUICtrlSetData($combo,"Reboot|Logoff|Display Message","Apagar") ;Groups GUICtrlCreateGroup("Current Time:",$MargenIzquierdo-5,$MargenSuperior-5,$AnchoVentana-10,$AltoEtiqueta+10) GUICtrlCreateGroup("Time of Event:", $MargenIzquierdo-5, $MargenSuperior+$Separador+10,$AnchoVentana-10,$AltoEtiqueta+10+$Separador) GUICtrlCreateGroup("Event:",$MargenIzquierdo-5,$MargenSuperior+$Separador*4+6,$AnchoVentana-10, $AltoEtiqueta+10+$Separador) ;Buttons $Aplicar=GUICtrlCreateButton("&Apply",$MargenIzquierdo+10,$MargenSuperior+$Separador*7+15,100,-1,$BS_DEFPUSHBUTTON) $Cancelar=GUICtrlCreateButton("&Cancel",$MargenIzquierdo+$Separador+105,$MargenSuperior+$Separador*7+15,100) ;Tray icon menu Opt("TrayOnEventMode",1) TrayCreateItem("About") TrayItemSetOnEvent(-1, "about") TrayCreateItem("") TrayCreateItem("New event") TrayItemSetOnEvent(-1, "nueva_hora") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "app_close") TraySetToolTip("Currently Idle") GUISetState() $MediElTiempo=False $loop = 0 While $loop = 0     ;=========================     ;Refreshes current time every 4 seconds.     if Not $MediElTiempo Then         $Empezar = TimerInit()         $MediElTiempo = True     EndIf     $dif = TimerDiff($Empezar)     if $dif>4000 Then         refrescar_reloj()         $MediElTiempo = False     EndIf       ;=========================     $msg=GUIGetMsg()     Select     Case $msg = $GUI_EVENT_CLOSE         $loop=1     Case $msg = $Aplicar                 ;==========================================                 ;Checks if the entered numbers have two digits. If they don't, it adds a 0.                 $largo1=StringLen(GUICtrlRead($HoraApagado))                 If $largo1<2 Then                     GUICtrlSetData($HoraApagado,"0"&GUICtrlRead($HoraApagado))                 EndIf                 $largo2=StringLen(GUICtrlRead($MinApagado))                 If $largo2<2 Then                     GUICtrlSetData($MinApagado,"0"&GUICtrlRead($MinApagado))                 EndIf                 ;============================================                 If GUICtrlRead($combo)="Display Message" Then                     $Mensaje=InputBox("Message","Type the message that you would like to display at the selected time")                     If @error<>1 Then                         funcionar()                     Else                     EndIf                 Else                     funcionar()                 EndIf     Case $msg=$Cancelar         $loop=1     EndSelect WEnd Func refrescar_reloj()     GUICtrlSetData($Reloj,@HOUR&":"&@MIN) EndFunc Func about()     MsgBox(0,"About","Author: Nahuel José"&@CRLF&"E-mail: nahueljose@gmail.com"&@CRLF&@CRLF&"Language:AutoIt"&@CRLF&"www.autoitscript.com") EndFunc Func app_close()     Dim $iMsgBoxAnswer     $iMsgBoxAnswer = MsgBox(52,"Exit","Really quit?")     Select        Case $iMsgBoxAnswer = 6 ;Yes         Exit        Case $iMsgBoxAnswer = 7 ;No     EndSelect EndFunc Func nueva_hora()     If $loop2=0 Then     Dim $iMsgBoxAnswer2         $iMsgBoxAnswer2 = MsgBox(36,"New Event","Restart timer and select new time and event?")         Select            Case $iMsgBoxAnswer2 = 6 ;Yes                 $loop2=1                 GUISetState(@SW_SHOW)                 TraySetToolTip("Currently Idle")            Case $iMsgBoxAnswer2 = 7 ;No            EndSelect     Else         $loop2=1         GUISetState(@SW_SHOW)         TraySetToolTip("Currently Idle")     EndIf EndFunc Func apagar()     ProcessClose("explorer.exe")     Shutdown(9);Shutdown EndFunc Func reiniciar()     ProcessClose("explorer.exe")     Shutdown(2);Reboot EndFunc Func cerrar_sesion()     Shutdown(0);Logoff EndFunc Func funcionar()     TraySetToolTip("Event: "&GUICtrlRead($combo)&". Time of Event: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado))     MsgBox(0,Guictrlread($combo),"Time for selected event: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado))     GUISetState(@SW_HIDE)     $loop2=0     $MediElTiempo1=False     While $loop2=0         If @HOUR=GUICtrlRead($HoraApagado) And @MIN=GUICtrlRead($MinApagado) Then         Select             ;SHUTDOWN         Case GUICtrlRead($combo)="Shutdown"                 Dim $iMsgBoxAnswer3                 $iMsgBoxAnswer3 = MsgBox(49,"Shutdown","Will shutdown in 5 seconds",5)                 Select                    Case $iMsgBoxAnswer3 = 1 ;Yes                     apagar()                    Case $iMsgBoxAnswer3 = 2 ;No                     Exit                    Case $iMsgBoxAnswer3 = -1;TimeOut                     apagar()                     Exit                 EndSelect             ;REBOOT         Case GUICtrlRead($combo)="Reboot"                 Dim $iMsgBoxAnswer4                 $iMsgBoxAnswer4 = MsgBox(49,"Reboot","Will reboot in 5 seconds",5)                 Select                    Case $iMsgBoxAnswer4 = 1 ;Yes                     reiniciar()                    Case $iMsgBoxAnswer4 = 2 ;No                     Exit                    Case $iMsgBoxAnswer4 = -1;TimeOut                     reiniciar()                 EndSelect             ;LOGOFF         Case GUICtrlRead($combo)="LOGOFF"                 Dim $iMsgBoxAnswer5                 $iMsgBoxAnswer5 = MsgBox(49,"LOGOFF","Will logoff in 5 seconds",5)                 Select                    Case $iMsgBoxAnswer5 = 1 ;Yes                     cerrar_sesion()                     Exit                    Case $iMsgBoxAnswer5 = 2 ;No                     Exit                    Case $iMsgBoxAnswer5 = -1;TimeOut                     cerrar_sesion()                     Exit                 EndSelect         Case GUICtrlRead($combo)="Display Message"                 SoundPlay(@windowsdir&"\media\tada.wav")                 MsgBox(0,"Message!",$Mensaje)                 Exit         EndSelect                         EndIf     WEnd EndFunc



Download Shutdown/Reboot/Logoff Timer - Compiled

This post has been edited by Nahuel: 13 August 2007 - 04:02 AM


#2 User is offline   Nahuel 

  • To Err is human, to Arr is pirate.
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,841
  • Joined: 25-June 07
  • Location:Argentina

Posted 10 August 2007 - 09:16 PM

I fixed a couple of problems that it had. Works fine now.

#3 User is offline   ScriptLearner 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 31
  • Joined: 06-August 07
  • Location:New Zeland

Posted 10 August 2007 - 10:55 PM

View PostNahuel, on Aug 11 2007, 02:56 AM, said:

Well... I wanted to share my timer with you guys. I find it pretty useful when I leave the computer on to download something and go to sleep or leave the house.

If you can check it out, tell me what you think :)
[ autoIt ]    ( ExpandCollapse - Popup )
#include <GuiConstants.au3> $loop2=1 $AnchoVentana = 250 $AltoVentana = 200 $MargenIzquierdo=10 $MargenSuperior=10 $Separador=20 $AnchoEtiqueta=130 $AltoEtiqueta=22 Opt("TrayAutoPause",0) Opt("TrayMenuMode",1) GuiCreate("Timer", $AnchoVentana, $AltoVentana) ;Current time: $Reloj=GUICtrlCreateLabel(@HOUR&":"&@MIN,$AnchoVentana/2-$Separador,$MargenSuperior+6,$AnchoEtiqueta) GUICtrlSetFont($Reloj, 10, 500, "", "Verdana") ;Hour $HoraApagado = GUICtrlCreateInput ("00",$MargenIzquierdo+5,$MargenSuperior+$Separador*2+10, 60, 20) GUICtrlCreateUpdown($HoraApagado) GUICtrlSetLimit(-1, 23,00) GUICtrlSetLimit($HoraApagado, 2) GUICtrlCreateLabel("Hours",$MargenIzquierdo+5+65,$MargenSuperior+$Separador*2+12) ;Minutes $MinApagado = GUICtrlCreateInput ("00",$MargenIzquierdo+$Separador+100,$MargenSuperior+$Separador*2+10, 60, 20) GUICtrlCreateUpdown($MinApagado) GUICtrlSetLimit(-1, 59,00) GUICtrlSetLimit($MinApagado, 2) GUICtrlCreateLabel("Minutes",$MargenIzquierdo+$Separador+100+65,$MargenSuperior+$Separador*2+12) ;Events $combo=GUICtrlCreateCombo("Shutdown",$MargenIzquierdo+5,$MargenSuperior+$Separador*4+25,220,200) GUICtrlSetData($combo,"Reboot|Logoff","Apagar") ;Groups GUICtrlCreateGroup("Current Time:",$MargenIzquierdo-5,$MargenSuperior-5,$AnchoVentana-10,$AltoEtiqueta+10) GUICtrlCreateGroup("Time of Event:", $MargenIzquierdo-5, $MargenSuperior+$Separador+10,$AnchoVentana-10,$AltoEtiqueta+10+$Separador) GUICtrlCreateGroup("Event:",$MargenIzquierdo-5,$MargenSuperior+$Separador*4+6,$AnchoVentana-10, $AltoEtiqueta+10+$Separador) ;Buttons $Aplicar=GUICtrlCreateButton("&Apply",$MargenIzquierdo+10,$MargenSuperior+$Separador*7+15,100,-1,$BS_DEFPUSHBUTTON) $Cancelar=GUICtrlCreateButton("&Cancel",$MargenIzquierdo+$Separador+105,$MargenSuperior+$Separador*7+15,100) ;Tray icon menu Opt("TrayOnEventMode",1) TrayCreateItem("About") TrayItemSetOnEvent(-1, "about") TrayCreateItem("") TrayCreateItem("New event") TrayItemSetOnEvent(-1, "nueva_hora") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "app_close") TraySetToolTip("Currently Idle") GUISetState() $MediElTiempo=False $loop = 0 While $loop = 0     ;=========================     ;Refreshes current time every 4 seconds.     if Not $MediElTiempo Then         $Empezar = TimerInit()         $MediElTiempo = True     EndIf     $dif = TimerDiff($Empezar)     if $dif>4000 Then         refrescar_reloj()         $MediElTiempo = False     EndIf       ;=========================     $msg=GUIGetMsg()     Select     Case $msg = $GUI_EVENT_CLOSE         $loop=1     Case $msg = $Aplicar             ;==========================================             ;Checks if the entered numbers have two digits. If they don't, it adds a 0.             $largo1=StringLen(GUICtrlRead($HoraApagado))             If $largo1<2 Then                 GUICtrlSetData($HoraApagado,"0"&GUICtrlRead($HoraApagado))             EndIf             $largo2=StringLen(GUICtrlRead($MinApagado))             If $largo2<2 Then                 GUICtrlSetData($MinApagado,"0"&GUICtrlRead($MinApagado))             EndIf             ;============================================ ;~       TraySetToolTip("Event: "&GUICtrlRead($combo)&". Time of Event: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado))             MsgBox(0,Guictrlread($combo),"Time for selected event: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado))             GUISetState(@SW_HIDE)             $loop2=0             $MediElTiempo1=False             While $loop2=0                 TraySetToolTip("Event: "&GUICtrlRead($combo)&". Time of Event: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado))                 If @HOUR=GUICtrlRead($HoraApagado) And @MIN=GUICtrlRead($MinApagado) Then                 Select                     ;SHUTDOWN                 Case GUICtrlRead($combo)="Shutdown"                         Dim $iMsgBoxAnswer3                         $iMsgBoxAnswer3 = MsgBox(49,"Shutdown","Will shutdown in 5 seconds",5)                         Select                            Case $iMsgBoxAnswer3 = 1 ;Yes                             apagar()                            Case $iMsgBoxAnswer3 = 2 ;No                             Exit                            Case $iMsgBoxAnswer3 = -1;TimeOut                             apagar()                             Exit                         EndSelect                     ;REBOOT                 Case GUICtrlRead($combo)="Reboot"                         Dim $iMsgBoxAnswer4                         $iMsgBoxAnswer4 = MsgBox(49,"Reboot","Will reboot in 5 seconds",5)                         Select                            Case $iMsgBoxAnswer4 = 1 ;Yes                             reiniciar()                            Case $iMsgBoxAnswer4 = 2 ;No                             Exit                            Case $iMsgBoxAnswer4 = -1;TimeOut                             reiniciar()                         EndSelect                     ;LOGOFF                 Case GUICtrlRead($combo)="LOGOFF"                         Dim $iMsgBoxAnswer5                         $iMsgBoxAnswer5 = MsgBox(49,"LOGOFF","Will logoff in 5 seconds",5)                         Select                            Case $iMsgBoxAnswer5 = 1 ;Yes                             cerrar_sesion()                             Exit                            Case $iMsgBoxAnswer5 = 2 ;No                             Exit                            Case $iMsgBoxAnswer5 = -1;TimeOut                             cerrar_sesion()                             Exit                         EndSelect                 EndSelect                                     EndIf         WEnd     Case $msg=$Cancelar         $loop=1     EndSelect WEnd Func refrescar_reloj()     GUICtrlSetData($Reloj,@HOUR&":"&@MIN) EndFunc Func about()     MsgBox(0,"About","Author: Nahuel José"&@CRLF&"E-mail: nahueljose@gmail.com"&@CRLF&@CRLF&"Language:AutoIt"&@CRLF&"www.autoitscript.com") EndFunc Func app_close()     Dim $iMsgBoxAnswer     $iMsgBoxAnswer = MsgBox(52,"Exit","Really quit?")     Select        Case $iMsgBoxAnswer = 6 ;Yes         Exit        Case $iMsgBoxAnswer = 7 ;No     EndSelect EndFunc Func nueva_hora()     If $loop2=0 Then     Dim $iMsgBoxAnswer2         $iMsgBoxAnswer2 = MsgBox(36,"New Event","Restart timer and select new time and event?")         Select            Case $iMsgBoxAnswer2 = 6 ;Yes                 $loop2=1                 GUISetState(@SW_SHOW)                 TraySetToolTip("Currently Idle")            Case $iMsgBoxAnswer2 = 7 ;No            EndSelect     Else         $loop2=1         GUISetState(@SW_SHOW)         TraySetToolTip("Currently Idle")     EndIf EndFunc Func apagar()     Shutdown(9);Shutdown EndFunc Func reiniciar()     Shutdown(2);Reboot EndFunc Func cerrar_sesion()     Shutdown(0);Logoff EndFunc

Here you can download the compiled .exe file.


Nice Work Working Good For AFK Well

Thanks

-Scirpt-Learner®™

#4 User is offline   Nahuel 

  • To Err is human, to Arr is pirate.
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,841
  • Joined: 25-June 07
  • Location:Argentina

Posted 11 August 2007 - 12:01 AM

Thanks! But I just noticed something that's wrong... :">

You see, I put this:
[ code='text' ]    ( Popup )
TraySetToolTip("Event: "&GUICtrlRead($combo)&". Time of Event: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado))

Inside the second loop, which is EATING OUT the cpu!! So I took it out of there, cause it was totally unnecessary.
I also limited the imput to 2 digits and made it check if the time entered has bigger numbers than 23hours and 59minutes.

Check main post! :D

#5 User is offline   Nahuel 

  • To Err is human, to Arr is pirate.
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,841
  • Joined: 25-June 07
  • Location:Argentina

Posted 13 August 2007 - 04:03 AM

I added the "Display Message" function. I think it's quite useful since I forget dates and things very easily when I'm on the computer.
Oh well, I'll stop bumping the thread now.

#6 User is offline   Dieuz 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 224
  • Joined: 15-December 06

Posted 14 August 2007 - 11:49 PM

Woww sweet. thanks alot! I was looking for this kind of things.

#7 User is offline   Nahuel 

  • To Err is human, to Arr is pirate.
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,841
  • Joined: 25-June 07
  • Location:Argentina

Posted 15 August 2007 - 12:10 AM

haha, no problem :P

#8 User is offline   BullGates 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 43
  • Joined: 30-June 07
  • Location:Portugal

Posted 04 September 2007 - 10:03 PM

Do you know you have a GUI in XP for that: shutdown -i
edit: well not really the same, but may be useful to know this switch exists for a gui :)

This post has been edited by BullGates: 04 September 2007 - 10:07 PM


#9 User is offline   Skrip 

  • (Previously known as Firestorm)
  • PipPipPipPipPipPipPip
  • Group: Full Members
  • Posts: 2,265
  • Joined: 26-November 05
  • Gender:Male
  • Location:Look behind you...

Posted 04 September 2007 - 10:56 PM

Cool. You should make a setting so it checks if a window is there, when it closes it will shutdown.

#10 User is offline   Chris86 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 156
  • Joined: 06-June 07
  • Gender:Male

Posted 23 December 2007 - 02:49 AM

View PostFirestorm, on Sep 4 2007, 01:56 PM, said:

Cool. You should make a setting so it checks if a window is there, when it closes it will shutdown.

Yeh That would be cool :D,
Does any one know how to make this to a Vista Sidebar Gadget?

Could you add a function that shutdown/restart/log off/shows a message if the cpu usage is low(or that if cpu/internet usage of a program is low)

This post has been edited by Chris86: 23 December 2007 - 03:01 AM


#11 User is offline   Nahuel 

  • To Err is human, to Arr is pirate.
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,841
  • Joined: 25-June 07
  • Location:Argentina

Posted 23 December 2007 - 02:34 PM

Haha, this must be one of the first scripts I made! I guess I could make it some improvements :P

#12 User is offline   sensalim 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 228
  • Joined: 19-April 07

Posted 23 December 2007 - 03:48 PM

Works and looks nice. GJ!

Would be nice to have:
-Instead of giving it hours and minutes, how about typing 30 for "30 more minutes" or "45" or "90" -- so we don't have to do the 'time math' in our head :P.
---or have a predefined dropdown for an alternative input ie:

O Hour: [__] Minutes: [__]
O [ 8:00][v]

where O is a radio button and [v] is a dropdown.

Thanks.

#13 User is offline   Nahuel 

  • To Err is human, to Arr is pirate.
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,841
  • Joined: 25-June 07
  • Location:Argentina

Posted 23 December 2007 - 10:04 PM

View Postsensalim, on Dec 23 2007, 11:48 AM, said:

Works and looks nice. GJ!

Would be nice to have:
-Instead of giving it hours and minutes, how about typing 30 for "30 more minutes" or "45" or "90" -- so we don't have to do the 'time math' in our head :P.
---or have a predefined dropdown for an alternative input ie:

O Hour: [__] Minutes: [__]
O [ 8:00][v]

where O is a radio button and [v] is a dropdown.

Thanks.


Hey that's not a bad idea! :D Thanks

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users