Sign in to follow this  
Followers 0
fatboy123

Littel help needed with this Shutdown script...

4 posts in this topic

Hello and thanks again to all you wonderful helpers,

I have this script in the task scheduler to run at 11:00 PM daily to shutdown the PC with the option to cancel,

1- I can't get the beep to sound correctly.

2- when the user presses cancel I want the window to close and the message to show.

3- is there a way to cancel for like 15 minutes and to start the shutdown process again?

#include <Constants.au3>
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$code = $SD_SHUTDOWN
$Elapse= 60000 ; 60 seconds
Beep()
GUICreate ("shuting Down the Computer", 400, 200, -1, -1, -1, $WS_EX_TOPMOST)
$progress=GUICtrlCreateProgress (110, 80, 200,30)
$cancel=GUICtrlCreateButton ("Cancel",160,130, 100)
$state=GUICtrlCreateLabel ("Windows is shutting down...",50,50, 150)
GuiCtrlSetState (-1, $GUI_HIDE)
GuiSetState()
$start = TimerInit()
Do
  $msg=GuiGetMsg()
  $diff=TimerDiff($start)
  if  $diff>=$elapse then
      Shutdown($code)
      GuiCtrlSetState($cancel, $GUI_HIDE)
      GuiCtrlSetState($state, $GUI_SHOW)
;     exit
  EndIf
  Sleep (100)
  GuiCtrlSetData($progress, $diff*100/$elapse)
Until $msg=$GUI_EVENT_CLOSE OR $msg= $cancel
GuiCtrlSetState($state,$GUI_HIDE)
MSGBOX(0,"Remember","You have canceled, Don't forget to turn of PC manualy")

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

why the beep dont work i dont know

I think you have to use functions.

it somting like this.

#include <Constants.au3>
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

_Gui()

func _Gui()
$Elapse= 60000 ; 60 seconds

$maingui = GUICreate ("shuting Down the Computer", 400, 200, -1, -1, -1, $WS_EX_TOPMOST)
$progress = GUICtrlCreateProgress (110, 80, 200,30)
$cancel = GUICtrlCreateButton ("Cancel",160,130, 100)
$state = GUICtrlCreateLabel ("Windows is shutting down...",50,50, 150)
GuiCtrlSetState (-1, $GUI_HIDE)
GuiSetState()
$start = TimerInit()
While 1

$msg = GuiGetMsg()
$diff = TimerDiff($start)
Select
Case $msg = $GUI_EVENT_CLOSE
  Exit
Case $diff>=$elapse
  Shutdown($code)
  GuiCtrlSetState($cancel, $GUI_HIDE)
  GuiCtrlSetState($state, $GUI_SHOW)
Case $msg = $cancel
  _Wait () ; go to function _wait

WEnd
EndFunc


Func _Wait ()
GUIDelete($maingui)
sleep(900000) ; 15 min
_Gui()
EndFunc
Edited by BartW

Share this post


Link to post
Share on other sites

3- is there a way to cancel for like 15 minutes and to start the shutdown process again?

Here it is with a repeating 15 minute time extension button

#include <Constants.au3>
#include <GuiConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; Hide the tray icon so users don't just abort your script
Opt("TrayIconHide", 1)      ;0=show, 1=hide tray icon

$Timeout = 15 ; in minutes
$code = $SD_SHUTDOWN
$Elapse= 60000 ; 60 seconds
while 1
    ;Beep()
    $GUI = GUICreate ("shuting Down the Computer", 400, 200, -1, -1, -1, $WS_EX_TOPMOST)
    $progress=GUICtrlCreateProgress (110, 80, 200,30)
    $cancel=GUICtrlCreateButton ("Give me another " & $Timeout & " minutes",130,130, 150)
    $state=GUICtrlCreateLabel ("Windows is shutting down...",50,50, 150)
    GuiCtrlSetState (-1, $GUI_HIDE)
    $state1=GUICtrlCreateLabel ("Shuddown in " & int($elapse / 1000) & " seconds",50,50, 150) ; show them the seconds with the progress bar
    GuiSetState()
    $start = TimerInit()
    Do
        $msg=GuiGetMsg()
        $diff=TimerDiff($start)
        if  $diff>=$elapse then
            GuiCtrlSetState($cancel, $GUI_HIDE)
            GuiCtrlSetState($state1, $GUI_HIDE)
            GuiCtrlSetState($state, $GUI_SHOW)
            Shutdown($code)
         Exit
        EndIf
        Sleep (100)
        GuiCtrlSetData($progress, $diff*100/$elapse)
        GUICtrlSetData($state1, "Shuddown in " & String(int(($elapse - $diff)/1000)) & " seconds")
    Until $msg=$GUI_EVENT_CLOSE OR $msg= $cancel
    GUIDelete($gui) ; clear the gui out of memory while we don't need it
    Sleep($Timeout * 60000) ; wait $timeout minutes, then do it again
WEnd

Share this post


Link to post
Share on other sites

Thank you so much gentleman for the effort, the second example by Willi Chan is exactly what I needed.

God Bless.

Mohd.

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