Sign in to follow this  
Followers 0
Achilles

Shutdown system

7 posts in this topic

#1 ·  Posted (edited)

Hey I finished this a while ago and thought it might be useful to those people who download stuff at night and actually want to turn off their computer. All it does is turn you computer off when you want it too, but it's easier then doing the math and making a script like Sleep(3600000) then Shutdown(8)... let me know what you think...

#include<GuiStatusBar.au3>
#include<EditConstants.au3>
#include<GUIConstantsEx.au3>
#include <string.au3>
Global  $a = "Force: Forces your computer to shut down", $b = "Power down: Cuts the power to your computer", $c = "If you filled out" _
& " both time and timer, then the specified time takes preference", $d = "Make sure you time format is right (i.e. 7:45 PM)", $split = "", $plit = ""

$r = Random(1,4,1)
If $r = 1 then $r = $a
If $r = 2 then $r = $b
If $r = 3 then $r = $c
If $r = 4 then $r = $d
Local $text[3] = [$r, "", ""],$edge[3] = [400, 1, 1], $split[1] = [""], $plit[1] = [""]

$gui = Guicreate("Shutdown", 390, 247)
GuiCtrlCreateGroup("What would you like to do?", 10, 10, 160, 205)
$shutdown = GuiCtrlCreateRadio("Shutdown", 35, 30, 80, 20)
    GuiCtrlSetState(-1, $Gui_Checked)
    $event = 1
    $main = $shutdown
$logoff = GuiCtrlCreateRadio("Log Off", 35, 60, 80, 20)
$reboot = GuiCtrlCreateRadio("Reboot", 35, 90, 80, 20)
$hibernate = GuiCtrlCreateRadio("Hibernate", 35, 120, 80, 20)
$force = GuiCtrlCreateCheckbox("Force", 35, 150, 80, 20)
$powerdown = GuiCtrlCreateCheckbox("Power down", 35, 180, 80, 20)

GuiCtrlCreateGroup("When --  Fill in either option", 180, 10, 195, 160)
GuiCtrlCreateLabel("Fill in timer for a countdown:", 190, 30, 180, 20)
GuiCtrlCreateLabel("How many minutes?", 200, 53, 100, 20)
$minute = GuiCtrlCreateInput("", 310, 50, 30, 20, $ES_NUMBER)
GuiCtrlCreateLabel("How many hours?", 200, 76, 100, 20)
$hour = GuiCtrlCreateInput("", 310, 73, 30, 20, $ES_NUMBER)
GuiCtrlCreateLabel("Or fill in the time:", 190, 110, 180, 20)
$time = GuiCtrlCreateInput("HH:MM PM/AM", 200, 135, 150, 20, $ES_CENTER)
$go = GuiCtrlCreateButton("Start timer or set time", 180, 180, 195, 35)
$StatusBar = _GUICtrlStatusBar_Create($gui, $edge, $text)
GuiSetState()

Do
    $msg = GuiGetMsg()
        If $msg = $GUI_EVENT_CLOSE then Exit
        If $msg = $logoff then 
            $logoff = $main
            $event = 0
            Endif
        If $msg = $shutdown then 
            $shutdown = $main
            $event = 1
            Endif
        If $msg = $reboot then
            $reboot = $main
            $event = 2
            Endif
        If $msg = $hibernate then 
            $hibernate = $main
            $event = 64
            Endif
        If $msg = $go Then
            $time = GuiCtrlRead($time)
            $hour = Number(GuiCtrlRead($hour))
            $minute = Number(GuiCtrlRead($minute))
            If $event = 0 then $name = "log off"
            If $event = 1 then $name = "turn off"
            If $event = 2 then $name = "reboot"
            If $event = 64 then $name = "hibernate"
            If $hour = 0 And $minute = 0 And $time = "HH:MM PM/AM" Then 
                Msgbox(0, "Error", "Please insert a time in at least one input box")
            Else
                If $time <> Bitor("", "HH:MM PM/AM") then 
                    $split = Stringsplit($time, ":")
                    $plit = Stringsplit($split[2], " ")
                    If Stringlen($split[1]) = 1 then $split[1] = _StringInsert($split[1], "0", 0)
                    If $plit[2] = "PM" then 
                        $split[1] += 12
                        EndIf
                    If $split[1] = "24" then $split[1] = "00"
                    _GUICtrlStatusBar_SetText($statusbar, "Your computer will " & $name & " at " & $time)
                    GuiCtrlSetState($go, $GUI_DISABLE)
                    $hour = 0
                    $minute = 0
                    $time = " "
                Endif
                If $hour <> 0 or $minute <> 0 then 
                    $hour2 = $hour * 3600000
                    $minute2 = $minute * 60000
                    GuiCtrlSetState($go, $GUI_DISABLE)

                    $minute = String($minute)
                    $hour = String($hour)
                    If Stringlen($minute) < 2 then $minute = _StringInsert($minute, "0", 0)
                    _GUICtrlStatusBar_SetText($statusbar, "Your computer will " & $name & " after " & $hour & ":" & $minute & " have passed")
                    $timer = TimerInit()
                    While TimerDiff($hour2 + $minute2) > TimerDiff($timer)
                        If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
                        Sleep(10)
                    Wend
                    If BitAnd(GUICtrlRead($force),$GUI_CHECKED) = $Gui_Checked then $event += 4
                    If BitAnd(GUICtrlRead($powerdown),$GUI_CHECKED) = $Gui_Checked then $event += 8
                    Shutdown($event)
                    Exit
                Endif
                Do 
                    If $split[1] = @Hour and $plit[1] = @MIN then 
                        If BitAnd(GUICtrlRead($force),$GUI_CHECKED) = $Gui_Checked then $event += 4
                        If BitAnd(GUICtrlRead($powerdown),$GUI_CHECKED) = $Gui_Checked then $event += 8
                        Shutdown($event)
                        Exit
                        Endif
                    Sleep(1000)
                Until $msg = $GUI_EVENT_CLOSE
            Endif
        Endif
Until $msg = $GUI_EVENT_CLOSE
Edited by Achilles

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites



Uhh, Think you forgot something?

Sins there is no code....

But a comment anyway.

Can I select the computer to shut down when network traffic is low, disk access is low and CPU usage less than 1% for 3min?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Uhh, Think you forgot something?

Sins there is no code....

But a comment anyway.

Can I select the computer to shut down when network traffic is low, disk access is low and CPU usage less than 1% for 3min?

Alright I added the script. And um, no... Nothing that complicated. Is there a way you can see the CPU usage with autoit though'cause I think that would be pretty simple if you could see the CPU usage. I'm not sure how I would do the network traffic part though...

Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hey I finished this a while ago and thought it might be useful to those people who download stuff at night and actually want to turn off their computer. All it does is turn you computer off when you want it too, but it's easier then doing the math and making a script like Sleep(3600000) then Shutdown(8)... let me know what you think...

Edit: Lol, I added the script

Not bad looking, but a cursory inspection (IE I ran it real quick) reveals there's insufficent validation (if any) on the time field.

For example "23:00 AM" is apparently a valid time, though who knows when it will be met! Putting simply "23:00" caused a failure.

Why not use an "UpDown" control instead of a simple text field, radios to select AM/PM and perhaps a Checkbox to enable 24hr clock?

And how about a cancel button?

~bxm

Edited by bluesxman

Share this post


Link to post
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
Sign in to follow this  
Followers 0