Jump to content

Shutdown/reboot/logoff Timer


Nahuel
 Share

Recommended Posts

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.

#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

Edited by Nahuel
Link to comment
Share on other sites

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 :)

#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®

Link to comment
Share on other sites

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

You see, I put this:

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! :)

Link to comment
Share on other sites

  • 3 weeks later...

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

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

  • 3 months later...

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 :),

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)

Edited by Chris86
Link to comment
Share on other sites

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 :).

---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.

Link to comment
Share on other sites

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 :).

---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! :P Thanks
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...