Jump to content

Shutdown *** V2 Now available ***


FreeRider
 Share

Recommended Posts

Hi all,

Following a request I received recently, I developed a small tool which shuts down the computer automatically (with progress bar) after a certain delay (this can be customised)

and gives the possibility for the user to abort or confirm the process. A good way to use it would be to place it into the Windows scheduler. It's useful when you need to power off a lot of computer at

the same time (classrooms)

Here is the code (you also can download the attached file which contains exactly the same code as below...)

#cs
Autoit Version :    v3.2.10.0
Author :            Christophe Savard (France)
Script Function :   Automatic shutdown programm with the possibility for the user to abort the process or confirm (accelerate) the shutdown.
Requirements :      IE5 or later.
#ce

#include <GUIConstants.au3>
Opt("GUICoordMode",0)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
$Mode = ""
$Delay = 20; delay before shutdown in seconds
$NewDelay = $Delay
$ShutMode = 1+4+8; Shutdown + Force + Powerdown ==> Play with this to choose your own options (see shutdown command help in Autoit help file)
$Pid = 4; Process Id of the process "System" (should be always 4 but verify and change if necessary)
$GuiWidth = 300
$GuiHeight = 130
$GuiTitle = "Shutdown Scheduler"
$PrgValue = 100

$GUI = GUICreate($GuiTitle,$GuiWidth,$GuiHeight)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Abort")
$LabelText = "System shutdown process is launched..."
GUICtrlCreateLabel($LabelText,20,15,StringLen($LabelText)*10,20)
$Progress = GUICtrlCreateProgress(-1,20,$GuiWidth-40,20,$PBS_SMOOTH )
GUICtrlSetData($Progress,$PrgValue); Sets the progress bar to 100%
$RemainLblText = "Remaining time (in seconds) before shutdwon : "
$RemainLbl = GUICtrlCreateLabel($RemainLblText & "20",-1,25,StringLen($RemainLblText)*10)
$AbortButLen=Stringlen("Abort")*8
$Abort = GUICtrlCreateButton("Abort",-1,$GuiHeight-100,$AbortButLen,30)
GUICtrlSetOnEvent($Abort,"_Abort")
GUICtrlSetTip ( $Abort, "Click Abort to stop the shutdown immediately.", GUICtrlRead($Abort,1),1,1)
$ConfirmButLen = Stringlen("Confirm")*8
$Confirm = GUICtrlCreateButton("Confirm",$AbortButLen +15,-1,$ConfirmButLen,30)
GUICtrlSetOnEvent($Confirm,"_Shutdown")
GUICtrlSetTip ( $Confirm, "Click Confirm to launch an immediate shutdown.", GUICtrlRead($Confirm,1),1,1)
GUISetState(@SW_SHOW)


Func _Abort ()
    GUICtrlSetData($RemainLbl,"Shutdown procedure has been aborted by user !")
    MsgBox(262144+16,$GuiTitle,"Shutdown process has been canceled by yourself !",2); After 2 seconds msgbox is deleted and script stops
    _Quit (); Exit script
EndFunc

Func _Shutdown ($Mode = "")
    $PrgValue=0
    GUICtrlSetData($Progress,$PrgValue)
    GUICtrlSetData($RemainLbl,"Please wait while system's shutting down...")
    If $Mode = "" Then; Message only displayed when manually confirmed
        MsgBox(262144+16,$GuiTitle,"Shutdown process has been confirmed by yourself !",2); After 2 seconds msgbox is deleted and shutdown process is started
    EndIf
    
    Shutdown($ShutMode)
    
    while 1; waiting loop
        If ProcessExists($Pid) Then; Waits for Process "System" to close
            If $PrgValue = 100 then $PrgValue = 0
            $PrgValue=$PrgValue+10
            GUICtrlSetData($Progress,$PrgValue)
        Else; Process does not exists.. It's time to exit...
            _Quit ()
        EndIf
        Sleep (1000)
    WEnd
EndFunc

Func _Quit ()
    Exit
EndFunc

While 1
    If GUICtrlRead ($Progress) = 0 Then _Shutdown ("AUTO"); Delay is over... it's time to shutdown
    Sleep (800)
    $NewDelay = $NewDelay-1; Calculates the new value for the remaining time before shutdown
    $PrgValue = ($NewDelay / $Delay) *100
    GUICtrlSetData($Progress,$PrgValue); Sets the progress bar to the new value
    GUICtrlSetData($RemainLbl,$RemainLblText & $NewDelay); Updates the remaining time in label
WEnd

Enjoy Scripting,

FreeRider

PS : OF COURSE FEEL FREE TO MODIFY, ADAPT OR DELETE THIS CODE...

** Updates **

2008/04/25 => Added : Language Management using Windows language coded in the registry

The script gets the current language of Windows and translates the displays (labels & messages).

Actual languages managed are English and French... If your own language if not English or French

and you don't include customised message in the script then the default language (English) is used.

Shutdown.au3

Edited by FreeRider

FreeRiderHonour & Fidelity

Link to comment
Share on other sites

don't want to be rude but... windows already has a pretty good tool for this :D

shutdown...

check out shutdown -i :D

cheers, alex

Edited by alexmadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

don't want to be rude but... windows already has a pretty good tool for this :D

shutdown...

check out shutdown -i :D

cheers, alex

Hehe that's what I thought until vista came along and restricted the shutdown -t XXX to 600 seconds. Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Hehe that's why I thought until vista came along and restricted the shutdown -t XXX to 600 seconds.

That pissed me off.. >,,<

Alright program though.

[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

Very nice program. I can use this to make sure my brother doesn't go on my computer after 9.. I think i will have to change the script a little... Not sure ill figure it out.. lol!

You could something much easier:

If @Hour = 21 then 
Shutdown(5)
EndIf

@OP: It's good so far but it would be better if the user could customize how long they want to wait.

Edit: I made this forever ago.. I don't even know if it still works but you could get some ideas from it.

Edited by Achilles
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Hi alexmadman,

In fact it means "quoi que", what I wanted to know is the sense of it (it's humor or not ?)

As Firestorm is much younger than I (he could be my son) I'm not sure we're on the same way with this "quoi que..."

Bye

i think though is "bien que" in french :D

FreeRiderHonour & Fidelity

Link to comment
Share on other sites

meh whatever i suck at french ^^

btw

Alright program though.

though has the sence of... anyway :

Anyway, nice program...

:D

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

Anyway, nice program...

That would be exactly what I meant.

[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

Thanks. Excellent program to help me cut a little power consumption (with autooff) without having the PC turn off on the user in the middle of things.

Request: It would be awesome of there were a way to have it shutdown another PC (that may not be possible on a peer-peer Windows network like the one I have).

Link to comment
Share on other sites

Hi Mr Analogy,

I have the same question pending.... I'm also looking a way to remotely shut down a computer (it must be possible).

When I'll have the way to do it found I'll post a updated version...

Bye

FreeRiderHonour & Fidelity

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