Jump to content

Call GUI multiple times


rbenner1184
 Share

Go to solution Solved by rbenner1184,

Recommended Posts

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

  • Moderators

rbenner1184,

This works fine for me when I test it with much shorted values - how about you: :huh:

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

; Set default values
$TimeToReboot = 60 ; 480 * 60 ;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."
;Set the reboot window with the command line options
If $cmdLine[0] = 3 Then
    $TimeToReboot = ($cmdLine[1] * 60)
    $WinTitle = $cmdLine[2]
    $InfoText = StringReplace($cmdLine[3], "\n", @CRLF) ; convert the return character
EndIf

;set up the timer and variables
$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)))

$Form1 = GUICreate($WinTitle, 418, 250, 198, 137, $WS_EX_TOPMOST) ; Force GUI to top <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$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, $Form1)
GUICtrlSetState($lblInformation, $GUI_FOCUS)

While 1

    ;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 = 30 Then ; 1800 Then ;30 minutes left, restore and bring to front
            GUISetState(@SW_SHOW, $Form1)
        EndIf
        If $TimeToReboot - $TimerCount = 20 Then ; 600 Then ;10 minutes left, restore and bring to front
            GUISetState(@SW_SHOW, $Form1)
        EndIf
        If $TimeToReboot - $TimerCount = 10 Then ; 30 Then ;30 seconds left, restore and bring to front
            GUISetState(@SW_SHOW, $Form1)
        EndIf

        ;Set the previous time
        $PrevTime = $TimerCount
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE ,$btnPostone ; Closing GUI = postpone <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            GUISetState(@SW_HIDE, $Form1)
        Case $btnReboot
            Shutdown(6) ;force reboot the system
    EndSwitch
WEnd
I made a couple of minor changes - see if you like them. Please ask if anything is unclear. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Solution

rbenner1184,

This works fine for me when I test it with much shorted values - how about you: :huh:

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

; Set default values
$TimeToReboot = 60 ; 480 * 60 ;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."
;Set the reboot window with the command line options
If $cmdLine[0] = 3 Then
    $TimeToReboot = ($cmdLine[1] * 60)
    $WinTitle = $cmdLine[2]
    $InfoText = StringReplace($cmdLine[3], "\n", @CRLF) ; convert the return character
EndIf

;set up the timer and variables
$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)))

$Form1 = GUICreate($WinTitle, 418, 250, 198, 137, $WS_EX_TOPMOST) ; Force GUI to top <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$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, $Form1)
GUICtrlSetState($lblInformation, $GUI_FOCUS)

While 1

    ;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 = 30 Then ; 1800 Then ;30 minutes left, restore and bring to front
            GUISetState(@SW_SHOW, $Form1)
        EndIf
        If $TimeToReboot - $TimerCount = 20 Then ; 600 Then ;10 minutes left, restore and bring to front
            GUISetState(@SW_SHOW, $Form1)
        EndIf
        If $TimeToReboot - $TimerCount = 10 Then ; 30 Then ;30 seconds left, restore and bring to front
            GUISetState(@SW_SHOW, $Form1)
        EndIf

        ;Set the previous time
        $PrevTime = $TimerCount
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE ,$btnPostone ; Closing GUI = postpone <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            GUISetState(@SW_HIDE, $Form1)
        Case $btnReboot
            Shutdown(6) ;force reboot the system
    EndSwitch
WEnd
I made a couple of minor changes - see if you like them. Please ask if anything is unclear. :)

M23

 

Yes this works and this is what I was having problems with. Thanks alot! :D

Link to comment
Share on other sites

  • Moderators

rbenner1184,

Glad I could help. :)

M23

Edited by Melba23
19k

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

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