Jump to content

TimeOut (Sleep) used in a GUI?


Gnat
 Share

Recommended Posts

I am working on a login script, that when run, has a default choice. I would like the script to wait 3 seconds to see if the user changes the default, and if they don't, I want the script to then run.

Here is a sample of my code, but I don't know where to do the "timeout" part...any help would be appreciated...

#include <GUIConstants.au3>

Global $SHELL32DLL = @SystemDir & "\SHELL32.dll"

Global $GUI, $logonServer, $gcpLogo, $gceInfoWindow

Global $DomainName = @LogonDomain

Global $UserName = @UserName

Global $updates, $gcgScriptDecision, $gcpScriptProgress

Global $colItems, $objItem, $FullName, $Name, $PasswordExpires

;#NoTrayIcon

Opt('GUICloseOnESC', 0); 1 = ESC closes / 0 = ESC won't close

Opt('GUIEventOptions', 1); 0=default, 1=just notification, 2=GuiCtrlRead tab index

Opt('TrayIconDebug', 0); 0=no info, 1=debug line info

;Opt('TrayMenuMode', 1); 0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return

Opt('TrayOnEventMode', 1); 0=disable, 1=enable

;********************************************************************************

;* Script body

;********************************************************************************

_UserDomainInfo()

$GUI = GUICreate('Logon Script', 344, 443, 20, 20)

GUISetIcon($SHELL32DLL, 21, $GUI)

$gcpLogo = GUICtrlCreatePic(@LogonServer & '\NETLOGON\Utils\Logo.bmp', 130, 10, 80, 30)

$gceInfoWindow = GUICtrlCreateEdit('', 24, 50, 296, 130, $ES_READONLY)

GUICtrlSetBkColor($gceInfoWindow, 0xffffff)

GUICtrlSetData($gceInfoWindow, 'Full Name: ' & $FullName & @CRLF & 'Username: ' & @UserName & @CRLF & 'Password Expires On: ' & _

$PasswordExpires & @CRLF & 'Workstation: ' & @ComputerName & @CRLF & 'Logon Server: ' & @LogonServer & @CRLF & _

'Date/Time: ' & @MON & '/' & @MDAY & '/' & @YEAR & ' ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF & @CRLF & _

'Please regularly reboot your PC to ensure that any' & @CRLF & 'important Security Updates and Patches are installed!')

$updates = GUICtrlCreateEdit('', 24, 181, 296, 184, $ES_READONLY)

GUICtrlSetBkColor($updates, 0xffffff)

$gcgScriptDecision = GUICtrlCreateGroup('Choose the script to run:', 24, 370, 296, 38)

$gcrProductionChoice = GUICtrlCreateRadio('Production', 160, 387, 70, 10)

$gcrBetaChoice = GUICtrlCreateRadio('Beta', 250, 387, 50, 10)

GUICtrlSetState($gcrProductionChoice, $GUI_CHECKED)

$gcpScriptProgress = GUICtrlCreateProgress(10, 413, 324, 20, $PBS_SMOOTH)

GUISetState (@SW_SHOW, $GUI)

While 1

Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE

GUIDelete($GUI)

Exit

Case $gcrProductionChoice

MsgBox(0, 'Test', 'Test')

EndSwitch

WEnd

;********************************************************************************

;* This section is for all functions. *

;********************************************************************************

Func _UserDomainInfo()

$wbemFlagReturnImmediately = 0x10

$wbemFlagForwardOnly = 0x20

$colItems = ''

$objWMIService = ObjGet('WinNT://' & $DomainName & '/' & $UserName & ',user')

$FullName = $objWMIService.Fullname

$objWMIService = ObjGet('winmgmts:\\localhost\root\cimv2')

$colItems = $objWMIService.ExecQuery('Select * from Win32_NetworkLoginProfile')

For $objItem in $colItems

$Name = $objItem.Name

If $Name = @LogonDomain & '\' & @UserName Then

$PasswordExpires = StringMid($objItem.PasswordExpires, 5, 2) & '/' & StringMid($objItem.PasswordExpires, 7,2) & _

'/' & StringLeft($objItem.PasswordExpires, 4) & ' ' & StringMid($objItem.PasswordExpires, 9, 2) & _

':' & StringMid($objItem.PasswordExpires, 11, 2) & ':' & StringMid($objItem.PasswordExpires, 13, 2)

EndIf

Next

EndFunc; _UserDomainInfo()

Link to comment
Share on other sites

Try this:

CODE
#include <GUIConstants.au3>
    
    Global $SHELL32DLL = @SystemDir & "\SHELL32.dll"
    Global $GUI, $logonServer, $gcpLogo, $gceInfoWindow
    Global $DomainName = @LogonDomain
    Global $UserName = @UserName
    Global $updates, $gcgScriptDecision, $gcpScriptProgress
    Global $colItems, $objItem, $FullName, $Name, $PasswordExpires
    
    ;#NoTrayIcon
    Opt('GUICloseOnESC', 0); 1 = ESC closes / 0 = ESC won't close
    Opt('GUIEventOptions', 1); 0=default, 1=just notification, 2=GuiCtrlRead tab index
    Opt('TrayIconDebug', 0); 0=no info, 1=debug line info
    ;Opt('TrayMenuMode', 1); 0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return
    Opt('TrayOnEventMode', 1); 0=disable, 1=enable
    
    
    ;********************************************************************************
    ;* Script body
    ;********************************************************************************
    
    _UserDomainInfo()
    
    $GUI = GUICreate('Logon Script', 344, 443, 20, 20)
    GUISetIcon($SHELL32DLL, 21, $GUI)
    
    $gcpLogo = GUICtrlCreatePic(@LogonServer & '\NETLOGON\Utils\Logo.bmp', 130, 10, 80, 30)
    $gceInfoWindow = GUICtrlCreateEdit('', 24, 50, 296, 130, $ES_READONLY)
    GUICtrlSetBkColor($gceInfoWindow, 0xffffff)
    GUICtrlSetData($gceInfoWindow, 'Full Name: ' & $FullName & @CRLF & 'Username: ' & @UserName & @CRLF & 'Password Expires On: ' & _
            $PasswordExpires & @CRLF & 'Workstation: ' & @ComputerName & @CRLF & 'Logon Server: ' & @LogonServer & @CRLF & _
            'Date/Time: ' & @MON & '/' & @MDAY & '/' & @YEAR & ' ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF & @CRLF & _
            'Please regularly reboot your PC to ensure that any' & @CRLF & 'important Security Updates and Patches are installed!')
    
    $updates = GUICtrlCreateEdit('', 24, 181, 296, 184, $ES_READONLY)
    GUICtrlSetBkColor($updates, 0xffffff)
    
    $gcgScriptDecision = GUICtrlCreateGroup('Choose the script to run:', 24, 370, 296, 38)
    $gcrProductionChoice = GUICtrlCreateRadio('Production', 160, 387, 70, 10)
    $gcrBetaChoice = GUICtrlCreateRadio('Beta', 250, 387, 50, 10)
    GUICtrlSetState($gcrProductionChoice, $GUI_CHECKED)
    
    $gcpScriptProgress = GUICtrlCreateProgress(10, 413, 324, 20, $PBS_SMOOTH)
    
    GUISetState (@SW_SHOW, $GUI)
    
    AdlibEnable('ChooseScript',3000) ;set a timer for ChooseScript() to run in 3000 ms (3 seconds)
    
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($GUI)
                Exit
        EndSwitch
    WEnd
    
    ;********************************************************************************
    ;* Production / Beta functions. *
    ;********************************************************************************
    
    Func ChooseScript()
        If BitAnd(GUICtrlRead($gcrBetaChoice),$GUI_CHECKED) = $GUI_CHECKED Then
            BetaScript()
        Else
            ProductionScript()
        EndIf
        AdlibDisable() ;make sure the timer doesn't run again later
    EndFunc
    
    Func BetaScript()
        MsgBox(0, '', 'Running BETA script...')
        Exit
    EndFunc
    
    Func ProductionScript()
        MsgBox(0, '', 'Running PRODUCTION script...')
        Exit
    EndFunc
    
    ;********************************************************************************
    ;* This section is for all other functions. *
    ;********************************************************************************
    
    Func _UserDomainInfo()
        $wbemFlagReturnImmediately = 0x10
        $wbemFlagForwardOnly = 0x20
        $colItems = ''
        $objWMIService = ObjGet('WinNT://' & $DomainName & '/' & $UserName & ',user')
        $FullName = $objWMIService.Fullname
    
        $objWMIService = ObjGet('winmgmts:\\localhost\root\cimv2')
        $colItems = $objWMIService.ExecQuery('Select * from Win32_NetworkLoginProfile')
        For $objItem in $colItems
            $Name = $objItem.Name
            If $Name = @LogonDomain & '\' & @UserName Then
                $PasswordExpires = StringMid($objItem.PasswordExpires, 5, 2) & '/' & StringMid($objItem.PasswordExpires, 7,2) & _
                        '/' & StringLeft($objItem.PasswordExpires, 4) & ' ' & StringMid($objItem.PasswordExpires, 9, 2) & _
                        ':' & StringMid($objItem.PasswordExpires, 11, 2) & ':' & StringMid($objItem.PasswordExpires, 13, 2)
            EndIf
        Next
    EndFunc

I used the Adlib functions to create a similar effect to Javascript's setTimeout().

[size="4"]YOU SHALL NOT PARSE!![/size]
Link to comment
Share on other sites

  • 1 year later...

Try this:

#include <GUIConstants.au3>
    
    Global $SHELL32DLL = @SystemDir & "\SHELL32.dll"
    Global $GUI, $logonServer, $gcpLogo, $gceInfoWindow
    Global $DomainName = @LogonDomain
    Global $UserName = @UserName
    Global $updates, $gcgScriptDecision, $gcpScriptProgress
    Global $colItems, $objItem, $FullName, $Name, $PasswordExpires
    
    ;#NoTrayIcon
    Opt('GUICloseOnESC', 0); 1 = ESC closes / 0 = ESC won't close
    Opt('GUIEventOptions', 1); 0=default, 1=just notification, 2=GuiCtrlRead tab index
    Opt('TrayIconDebug', 0); 0=no info, 1=debug line info
    ;Opt('TrayMenuMode', 1); 0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return
    Opt('TrayOnEventMode', 1); 0=disable, 1=enable
    
    
    ;********************************************************************************
    ;* Script body
    ;********************************************************************************
    
    _UserDomainInfo()
    
    $GUI = GUICreate('Logon Script', 344, 443, 20, 20)
    GUISetIcon($SHELL32DLL, 21, $GUI)
    
    $gcpLogo = GUICtrlCreatePic(@LogonServer & '\NETLOGON\Utils\Logo.bmp', 130, 10, 80, 30)
    $gceInfoWindow = GUICtrlCreateEdit('', 24, 50, 296, 130, $ES_READONLY)
    GUICtrlSetBkColor($gceInfoWindow, 0xffffff)
    GUICtrlSetData($gceInfoWindow, 'Full Name: ' & $FullName & @CRLF & 'Username: ' & @UserName & @CRLF & 'Password Expires On: ' & _
            $PasswordExpires & @CRLF & 'Workstation: ' & @ComputerName & @CRLF & 'Logon Server: ' & @LogonServer & @CRLF & _
            'Date/Time: ' & @MON & '/' & @MDAY & '/' & @YEAR & ' ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF & @CRLF & _
            'Please regularly reboot your PC to ensure that any' & @CRLF & 'important Security Updates and Patches are installed!')
    
    $updates = GUICtrlCreateEdit('', 24, 181, 296, 184, $ES_READONLY)
    GUICtrlSetBkColor($updates, 0xffffff)
    
    $gcgScriptDecision = GUICtrlCreateGroup('Choose the script to run:', 24, 370, 296, 38)
    $gcrProductionChoice = GUICtrlCreateRadio('Production', 160, 387, 70, 10)
    $gcrBetaChoice = GUICtrlCreateRadio('Beta', 250, 387, 50, 10)
    GUICtrlSetState($gcrProductionChoice, $GUI_CHECKED)
    
    $gcpScriptProgress = GUICtrlCreateProgress(10, 413, 324, 20, $PBS_SMOOTH)
    
    GUISetState (@SW_SHOW, $GUI)
    
    AdlibEnable('ChooseScript',3000) ;set a timer for ChooseScript() to run in 3000 ms (3 seconds)
    
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($GUI)
                Exit
        EndSwitch
    WEnd
    
    ;********************************************************************************
    ;* Production / Beta functions. *
    ;********************************************************************************
    
    Func ChooseScript()
        If BitAnd(GUICtrlRead($gcrBetaChoice),$GUI_CHECKED) = $GUI_CHECKED Then
            BetaScript()
        Else
            ProductionScript()
        EndIf
        AdlibDisable() ;make sure the timer doesn't run again later
    EndFunc
    
    Func BetaScript()
        MsgBox(0, '', 'Running BETA script...')
        Exit
    EndFunc
    
    Func ProductionScript()
        MsgBox(0, '', 'Running PRODUCTION script...')
        Exit
    EndFunc
    
    ;********************************************************************************
    ;* This section is for all other functions. *
    ;********************************************************************************
    
    Func _UserDomainInfo()
        $wbemFlagReturnImmediately = 0x10
        $wbemFlagForwardOnly = 0x20
        $colItems = ''
        $objWMIService = ObjGet('WinNT://' & $DomainName & '/' & $UserName & ',user')
        $FullName = $objWMIService.Fullname
    
        $objWMIService = ObjGet('winmgmts:\\localhost\root\cimv2')
        $colItems = $objWMIService.ExecQuery('Select * from Win32_NetworkLoginProfile')
        For $objItem in $colItems
            $Name = $objItem.Name
            If $Name = @LogonDomain & '\' & @UserName Then
                $PasswordExpires = StringMid($objItem.PasswordExpires, 5, 2) & '/' & StringMid($objItem.PasswordExpires, 7,2) & _
                        '/' & StringLeft($objItem.PasswordExpires, 4) & ' ' & StringMid($objItem.PasswordExpires, 9, 2) & _
                        ':' & StringMid($objItem.PasswordExpires, 11, 2) & ':' & StringMid($objItem.PasswordExpires, 13, 2)
            EndIf
        Next
    EndFunc
I used the Adlib functions to create a similar effect to Javascript's setTimeout().
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...