Sign in to follow this  
Followers 0
Hyflex

Setting up a timer / delay a popup in a while without delaying other tasks

2 posts in this topic

#1 ·  Posted (edited)

Hey Guys,

I've been trying to get a delay/timer going for quite a while but am still having problems in doing so, below is a copy of my code that I'm using...

 

#include <ImageSearch.au3>
#include <MsgBoxConstants.au3>
 
; Misc Variables
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayAutoPause", 0)
 
TraySetClick(8)
 
$Tray_Exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "Terminate")
 
$SleepDelay = 100
 
If Not FileExists(@StartupDir & "\Anti-Sh1t.lnk") Then
    FileCreateShortcut( @ScriptDir & "\Anti-Sh1t.exe", @StartupDir & "\Anti-Sh1t.lnk")
    ConsoleWrite("Created" & @CRLF)
Else
    ConsoleWrite("NOT Created" & @CRLF)
EndIf
 
While 1
    If WinExists("Sponsored session") Then
        RWinWaitActivate("Sponsored session")
        ControlClick("Sponsored session", "", "[CLASS:Button; INSTANCE:4]")
        Sleep($SleepDelay)
    EndIf
 
    If WinExists("Commercial use") Then
        RWinWaitActivate("Commercial use")
        ControlClick("Commercial use", "", "[CLASS:Button; INSTANCE:4]")
        Sleep($SleepDelay)
    EndIf
 
    If WinExists("Skype™ - Update") Then
        $XCoords = ""
        $YCoords = ""
        RWinWaitActivate("Skype™ - Update")
        $SkypeNoUpdate = _ImageSearch(@DesktopDir & "\Images\" & "SkypeNoUpdate.png", 1, $XCoords, $YCoords, 25)
        While $SkypeNoUpdate = 0
            $SkypeNoUpdate = _ImageSearch(@DesktopDir & "\Images\" & "SkypeNoUpdate.png", 1, $XCoords, $YCoords, 25)
            Sleep(100)
        WEnd
        MouseClick("Left", $XCoords, $YCoords, 1, 1)
        Sleep($SleepDelay)
    EndIf
 
    If WinExists("Windows Update") Then
        RunWait(@ComSpec & ' /c ' & "net stop wuauserv", @TempDir, @SW_HIDE)
        Sleep($SleepDelay)
    EndIf
    
    ; PART THAT I CAN'T GET WORKING CORRECT
    If @HOUR & ":" & @MIN & ":" & @SEC >= "08:00:00" and @HOUR & ":" & @MIN & ":" & @SEC <= "11:30:00" Then
        ; If for the first loop on a new day or 30 mins have been since the last "Cancel" was pressed on the popup
            If ProcessExists("EXCEL.EXE") Then
                $ForceClosePop = MsgBox($MB_OKCANCEL, "Force Close 'EXCEL.EXE'?", "Press 'Okay' if you want to force close 'EXCEL.EXE`" & @LF & @LF & "Press 'Cancel' if you want to delay this action by a further 30 minutes" & @LF & @LF & "If you fail to choose within 10 minutes 'EXCEL.EXE' will be automatically killed.", 600)
                If $ForceClosePop = 1 Then
                    ; Okay was pressed...
                    If ProcessExists("EXCEL.EXE") Then
                        Do
                            ProcessClose('EXCEL.EXE')
                        Until Not ProcessExists('EXCEL.EXE')
                    EndIf
                ElseIf $ForceClosePop = 2 Then
                    ; Cancel was pressed...
                    ; I need to add a sort of sleep for 30 mins... but I don't wait it to stop/interupt the other part of the while loop.
                ElseIf $ForceClosePop = -1 Then
                    ; Timeout
                    If ProcessExists("EXCEL.EXE") Then
                        Do
                            ProcessClose('EXCEL.EXE')
                        Until Not ProcessExists('EXCEL.EXE')
                    EndIf
                EndIf
            EndIf
        ; EndIf...
    EndIf
 
WEnd
 
Func RWinWaitActivate($WWAVariable)
    WinWait($WWAVariable)
    WinActivate($WWAVariable)
    WinWaitActive($WWAVariable)
    Sleep(500)
EndFunc ;==>RWinWaitActivate
 
Func Terminate()
    Exit 0
EndFunc ;==>Terminate
The part of the script that I can't get working is the following:

    ; PART THAT I CAN'T GET WORKING CORRECT
    If @HOUR & ":" & @MIN & ":" & @SEC >= "08:00:00" and @HOUR & ":" & @MIN & ":" & @SEC <= "11:30:00" Then
        ; If for the first loop on a new day or 30 mins have been since the last "Cancel" was pressed on the popup
            If ProcessExists("EXCEL.EXE") Then
                $ForceClosePop = MsgBox($MB_OKCANCEL, "Force Close 'EXCEL.EXE'?", "Press 'Okay' if you want to force close 'EXCEL.EXE`" & @LF & @LF & "Press 'Cancel' if you want to delay this action by a further 30 minutes" & @LF & @LF & "If you fail to choose within 10 minutes 'EXCEL.EXE' will be automatically killed.", 600)
                If $ForceClosePop = 1 Then
                    ; Okay was pressed...
                    If ProcessExists("EXCEL.EXE") Then
                        Do
                            ProcessClose('EXCEL.EXE')
                        Until Not ProcessExists('EXCEL.EXE')
                    EndIf
                ElseIf $ForceClosePop = 2 Then
                    ; Cancel was pressed...
                    ; I need to add a sort of sleep for 30 mins... but I don't wait it to stop/interupt the other part of the while loop.
                ElseIf $ForceClosePop = -1 Then
                    ; Timeout
                    If ProcessExists("EXCEL.EXE") Then
                        Do
                            ProcessClose('EXCEL.EXE')
                        Until Not ProcessExists('EXCEL.EXE')
                    EndIf
                EndIf
            EndIf
        ; EndIf...
    EndIf
I've added some comments to show where I think the parts should be... Basically the function that I am missing is a way to delay/postpone the popup if the user presses cancel, similar to how Windows Update works but I don't want to use a Sleep(1800000) because that would mean all of the other parts of the script will be stuck for 30 minutes...

I want it ONLY to effect this specific part of the script, any ideas how to do it? I've tried using Timer/TimerDiff but have no idea how to work it out and get it working.

Any help would be much appreciated.

Edited by Hyflex

Share this post


Link to post
Share on other sites



this should work (not tested)

just added lines 24, 68, 89, 91 (marked with ; <---)

#include <ImageSearch.au3>
#include <MsgBoxConstants.au3>

; Misc Variables
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayAutoPause", 0)

TraySetClick(8)

$Tray_Exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "Terminate")

$SleepDelay = 100
Global $WaitHalfHour ; <--- declare a global variable

If Not FileExists(@StartupDir & "\Anti-Sh1t.lnk") Then
    FileCreateShortcut(@ScriptDir & "\Anti-Sh1t.exe", @StartupDir & "\Anti-Sh1t.lnk")
    ConsoleWrite("Created" & @CRLF)
Else
    ConsoleWrite("NOT Created" & @CRLF)
EndIf

While 1
    If WinExists("Sponsored session") Then
        RWinWaitActivate("Sponsored session")
        ControlClick("Sponsored session", "", "[CLASS:Button; INSTANCE:4]")
        Sleep($SleepDelay)
    EndIf

    If WinExists("Commercial use") Then
        RWinWaitActivate("Commercial use")
        ControlClick("Commercial use", "", "[CLASS:Button; INSTANCE:4]")
        Sleep($SleepDelay)
    EndIf

    If WinExists("Skype™ - Update") Then
        $XCoords = ""
        $YCoords = ""
        RWinWaitActivate("Skype™ - Update")
        $SkypeNoUpdate = _ImageSearch(@DesktopDir & "\Images\" & "SkypeNoUpdate.png", 1, $XCoords, $YCoords, 25)
        While $SkypeNoUpdate = 0
            $SkypeNoUpdate = _ImageSearch(@DesktopDir & "\Images\" & "SkypeNoUpdate.png", 1, $XCoords, $YCoords, 25)
            Sleep(100)
        WEnd
        MouseClick("Left", $XCoords, $YCoords, 1, 1)
        Sleep($SleepDelay)
    EndIf

    If WinExists("Windows Update") Then
        RunWait(@ComSpec & ' /c ' & "net stop wuauserv", @TempDir, @SW_HIDE)
        Sleep($SleepDelay)
    EndIf

    ; PART THAT I CAN'T GET WORKING CORRECT
    If @HOUR & ":" & @MIN & ":" & @SEC >= "08:00:00" And @HOUR & ":" & @MIN & ":" & @SEC <= "11:30:00" Then
        ; If for the first loop on a new day or 30 mins have been since the last "Cancel" was pressed on the popup
        If ProcessExists("EXCEL.EXE") Then
            If TimerDiff($WaitHalfHour) > 1800000 Then; if Half an hour was elapsed <---
                $ForceClosePop = MsgBox($MB_OKCANCEL, "Force Close 'EXCEL.EXE'?", "Press 'Okay' if you want to force close 'EXCEL.EXE`" & @LF & @LF & "Press 'Cancel' if you want to delay this action by a further 30 minutes" & @LF & @LF & "If you fail to choose within 10 minutes 'EXCEL.EXE' will be automatically killed.", 600)
                If $ForceClosePop = 1 Then
                    ; Okay was pressed...
                    If ProcessExists("EXCEL.EXE") Then
                        Do
                            ProcessClose('EXCEL.EXE')
                        Until Not ProcessExists('EXCEL.EXE')
                    EndIf

                ElseIf $ForceClosePop = -1 Then
                    ; Timeout
                    If ProcessExists("EXCEL.EXE") Then
                        Do
                            ProcessClose('EXCEL.EXE')
                        Until Not ProcessExists('EXCEL.EXE')
                    EndIf

                ElseIf $ForceClosePop = 2 Then
                    ; Cancel was pressed...
                    ; I need to add a sort of sleep for 30 mins... but I don't wait it to stop/interupt the other part of the while loop.
                    $WaitHalfHour = TimerInit() ; restart timer to 0 ; <---
                EndIf
            EndIf ; <---
        EndIf
    EndIf
WEnd

Func RWinWaitActivate($WWAVariable)
    WinWait($WWAVariable)
    WinActivate($WWAVariable)
    WinWaitActive($WWAVariable)
    Sleep(500)
EndFunc   ;==>RWinWaitActivate

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
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
Sign in to follow this  
Followers 0