Jump to content

Littel help needed with this Shutdown script...


 Share

Recommended Posts

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")
Link to comment
Share on other sites

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
Link to comment
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
Link to comment
Share on other sites

  • 6 years later...
2 minutes ago, sreeharsha said:

Hi Willichan, 

Is there a way where we can edit this script to repeat reboot only for 2 times and force reboot for 3rd time not giving an option to defer reboot.

 

Thanks in advance

still trying to get someone to do your work I see. The quality of the responses you get is proportional to the quality of the input and effort shown..... Show us your code that isn't working. Please use the CODE tags <> when posting code so we can easily copy and test.

My resources are limited. You must ask the right questions

 

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