rbenner1184 Posted January 30, 2014 Share Posted January 30, 2014 I am building a pretty complicated script that will install internet explorer 10 both offline and online and that part has been done, but since I am in an enterprise environment here this install will be going out to everyone in the company, especially senior executive officers so I do not want to make anyone angry. My goal is to ask the user if they want to reboot right away and reboot if the user agrees, but if they do not then the gui timer that I have compiled with a pop up counting down from 8 hours, but this also gives the user yet again another chance to postpone the reboot. If they do postpone the gui should sleep for 4 hours then pop up again. Then with 30 minutes remaining before the reboot this gui should pop up again. I have the timer down, but I cannot seem to to my script to call the timer up back after i tell it to sleep. Does anyone have any clue how I could achieve this? Here is the code if you have any ideas. Thank you. expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIConstants.au3> ;#include <StaticConstants.au3> ;Start reboot prompt If $cmdLine[0] = 0 then ;Set up the reboot window with the default settings $TimeToReboot = 480 ;8 hours $WinTitle = "IT" $InfoText = "Internet Explorer has been installed and requires the PC to restart. If the PC does not restart it will automatically restart in 8 hours." ;exit -1 ;not all arguments are present, reboot ElseIf $cmdLine[0] = 3 then ;Set the reboot window with the command line options $TimeToReboot = $cmdLine[1] $WinTitle = $cmdLine[2] $InfoText = $cmdLine[3] EndIf ;add the return character $InfoText = StringReplace($InfoText,"\n",@CRLF) ;set up the timer and variables $TimeToReboot *= 60 ;convert it to seconds $startTime = TimerInit() $TimerCount = int(TimerDiff($startTime) / 1000) ;return the time in seconds $PrevTime = $TimerCount $tHour = StringFormat("%02d",int(($TimeToReboot - $TimerCount) / 8 * 60 / 60)) $tMin = StringFormat("%02d",int(($TimeToReboot - $TimerCount - ($tHour * 60 * 60)) / 60)) $tSec = StringFormat("%02d",int($TimeToReboot - $TimerCount - ($tHour * 60 * 60) - ($tMin * 60))) ;msgbox(64,"num of args", $cmdLine[0] & @crlf & $cmdLine[1] & @crlf & $cmdLine[2] & @crlf & $cmdLine[3]) ;number of arguments #Region ### START Koda GUI section ### Form= $Form1 = GUICreate($WinTitle, 418, 250, 198, 137) $lblInformation = GUICtrlCreateLabel($InfoText, 16, 16, 386, 146, $WS_VSCROLL, $WS_EX_STATICEDGE) $lblTimerlbl = GUICtrlCreateLabel("Your PC will automatically restart in:", 16, 182, 200, 17) $lblTimer = GUICtrlCreateLabel($tHour & ":" & $tMin & ":" & $tSec, 216, 182, 60, 17) $btnPostone = GUICtrlCreateButton("Postpone", 180, 200, 107, 25, 0) $btnReboot = GUICtrlCreateButton("Restart Now", 296, 200, 107, 25, 0) GUISetState(@SW_SHOW) GUICtrlSetState($lblInformation,$GUI_FOCUS) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() ;do the timer stuff $TimerCount = int(TimerDiff($startTime) / 1000) ;return the time in seconds if $TimeToReboot - $TimerCount <= 0 Then Shutdown(6) ;Force a reboot Exit EndIf if $PrevTime <> $TimerCount Then ;update the counter $tHour = StringFormat("%02d",int(($TimeToReboot - $TimerCount) / 60 / 60)) $tMin = StringFormat("%02d",int(($TimeToReboot - $TimerCount - ($tHour * 60 * 60)) / 60)) $tSec = StringFormat("%02d",int($TimeToReboot - $TimerCount - ($tHour * 60 * 60) - ($tMin * 60))) ;Set the label GUICtrlSetData($lblTimer,$tHour & ":" & $tMin & ":" & $tSec) ;bring to front and restore window to inform the user its close to reboot time at certain intervals if $TimeToReboot - $TimerCount = 1800 then ;30 minutes left, restore and bring to front GUICtrlSetState($lblInformation,$GUI_FOCUS) GUISetState(@SW_RESTORE) EndIf if $TimeToReboot - $TimerCount = 600 then ;10 minutes left, restore and bring to front GUICtrlSetState($lblInformation,$GUI_FOCUS) GUISetState(@SW_RESTORE) EndIf if $TimeToReboot - $TimerCount = 30 then ;30 seconds left, restore and bring to front GUICtrlSetState($lblInformation,$GUI_FOCUS) GUISetState(@SW_RESTORE) EndIf ;Set the previous time $PrevTime = $TimerCount EndIf Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit Case $btnReboot Shutdown(6) ;force reboot the system Case $btnPostone;make reboot sleep $TimeToReboot Sleep(3000) EndSwitch WEnd ;EndIf Link to comment Share on other sites More sharing options...
SupaNewb Posted February 1, 2014 Share Posted February 1, 2014 expandcollapse popup#Include <GUIConstantsEx.au3> Global $Msg Global $hMainGui = GUICreate("NewScript", 100, 50) Global $bStartTimer = GUICtrlCreateButton("Start Timer", 10, 15, 80, 20) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE __MyExit() Case $bStartTimer __Timer() EndSwitch WEnd Func __Timer() Local $iRet, $hTimerStart, $iDiff $iRet = MsgBox(68, "Blah Blah header info here", "Select Yes To Reboot Now" & _ @CRLF & @CRLF & "Or Select No To Reboot Later") If $iRet = 6 Then;selected yes ;Call your rebooot Function here Return EndIf $hTimerStart = TimerInit() Do Sleep(60000);1 minute $iDiff = TimerDiff($hTimerStart) Until $iDiff = 1000 * 60 * 60 * 8;8 hours $iRet = MsgBox(68, "Blah Blah header info here", "Select Yes To Reboot Now" & _ @CRLF & @CRLF & "Or Select No To Reboot Later") If $iRet = 6 Then;selected yes ;Call your rebooot Function here Return EndIf Do Sleep(60000);1 minute $iDiff = TimerDiff($hTimerStart) Until $iDiff = 1000 * 60 * 60 * 4;4 hours Do Sleep(60000);1 minute $iDiff = TimerDiff($hTimerStart) Until $iDiff = 1000 * 60 * 30 ;30 minutes ;Call reboot Function here EndFunc ;==>__Timer Func __MyExit() GUIDelete($hMainGui) Exit EndFunc ;==>__MyExit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2014 Moderators Share Posted February 1, 2014 rbenner1184,I have just realised that you posted this question twice. Please do not double-post in this manner again. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts