fatboy123 Posted December 12, 2011 Share Posted December 12, 2011 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 More sharing options...
BartW Posted December 12, 2011 Share Posted December 12, 2011 (edited) why the beep dont work i dont know I think you have to use functions. it somting like this. expandcollapse popup#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 December 12, 2011 by BartW Link to comment Share on other sites More sharing options...
willichan Posted December 12, 2011 Share Posted December 12, 2011 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 expandcollapse popup#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 My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
fatboy123 Posted December 13, 2011 Author Share Posted December 13, 2011 Thank you so much gentleman for the effort, the second example by Willi Chan is exactly what I needed. God Bless. Mohd. Link to comment Share on other sites More sharing options...
sreeharsha Posted January 22, 2018 Share Posted January 22, 2018 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 Link to comment Share on other sites More sharing options...
Earthshine Posted January 22, 2018 Share Posted January 22, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now