Sign in to follow this  
Followers 0
rbenner1184

Calling up a GUI more than once

3 posts in this topic

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.

#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

Share this post


Link to post
Share on other sites



#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

Share this post


Link to post
Share on other sites

rbenner1184,

I have just realised that you posted this question twice. Please do not double-post in this manner again. :naughty:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0