Sign in to follow this  
Followers 0
Hyflex

Adding a timer / "suspend" feature to a msgbox...

9 posts in this topic

#1 ·  Posted (edited)

I have the following code running on my computer to get rid of certain annoying nags and frustrations fasteish...

 

#include <ImageSearch.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
        WinActivate("Sponsored session")
        WinWaitActive("Sponsored session")
        Sleep($SleepDelay)
        ControlClick("Sponsored session", "", "[CLASS:Button; INSTANCE:4]")
        Sleep($SleepDelay)
    EndIf

    If WinExists("Commercial use") Then
        WinActivate("Commercial use")
        WinWaitActive("Commercial use")
        Sleep($SleepDelay)
        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)
    EndIf

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

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

; Exit
Func Terminate()
    Exit 0
EndFunc
I'm trying to incorporate another feature to the script but am not quite sure how to do what I want to do...

 

#include <MsgBoxConstants.au3>

MsgBox($MB_OKCANCEL, "Force Close '101.exe'?", "Press 'Okay' if you want to force close '101.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 '101.exe' will be automatically killed.", 600)
Using the above, I basically want the following abilities:

1) At 08:30(am) till 11:30(am) it will start checking for "101.exe" and if present the above popup will appear.

2) If "Okay" is pressed, it would force close "101.exe"

3) If "Cancel" is pressed, it would stop the popup from appearing on the next loop(s) for 30 minutes, after that 30mins has been it should start again...

4) If neither button is pressed, it should automatically force close "101.exe"

I have no idea how to do the timer/time aspect of it...

Edited by Hyflex

Share this post


Link to post
Share on other sites



Can you clarify what you mean by "timer/time aspect"? If you mean this:


1) At 08:30(am) till 11:30(am) it will start checking for "101.exe" and if present the above popup will appear.

 

You can either compile the script and schedule when to run it through Task Scheduler, or look at _Now or _NowTime in the help file.

 

If you mean how long the MsgBox waits, it seems you already have this set at 600 seconds.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Hey JLogan3o13,

Sorry, I was having trouble wording it... Uhm.

The script/code is running 24/7 so I don't want to run it through task scheduler, I'll have a look at _Now and _NowTime for my first part.

In regards to the MsgBox waits... The timeout is set to 600 seconds yes but how do I detect if it timed out and if they press Cancel I want the popup to be suppressed for 30 minutes before popping up again

#include <MsgBoxConstants.au3>
$ForceClosePop = MsgBox($MB_OKCANCEL, "Force Close '101.exe'?", "Press 'Okay' if you want to force close '101.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 '101.exe' will be automatically killed.", 600)

If $ForceClosePop = 1 Then
   ; Okay was pressed...
ElseIf $ForceClosePop = 2 Then
   ; Cancel was pressed...
ElseIf $ForceClosePop = XXX Then
   ; Timeout?
EndIf

Share this post


Link to post
Share on other sites

Ok, that makes more sense. As KaFu points out (ltns, btw), check the return of your MsgBox to see if it timed out, and then move on accordingly.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Global $msg

_msg()

Func _msg()
$msg = msgbox (1, '' , "timeout or button press?" , 5)
If $msg <> -1 Then
    sleep(5000)
    _msg()
Else
    tooltip("msgbox timed out, after 5 seconds the script will exit" , 0 ,0)
    sleep (5000)
    Exit
EndIf
EndFunc


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

I don't understand the benefit of using NowTime...

 

#include <Date.au3>

If _NowTime() >= "08:00:00" Then
    ConsoleWrite(_NowTime() & @CRLF)
EndIf

If @HOUR & ":" & @MIN & ":" & @SEC >= "08:00:00" Then
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & @CRLF)
EndIf
They both do the same thing...?

 

 

I suggested that before you made clear what you were intending. Please disregard.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

#include <MsgBoxConstants.au3>

If @HOUR & ":" & @MIN & ":" & @SEC >= "08:00:00" and @HOUR & ":" & @MIN & ":" & @SEC <= "11:30:00" Then
    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
Struggling still with the If cancel was pressed part, I've had a look into using Timer but don't know how do it (can't even think of a logical way of doing it in my brain)

I need to add a sort of sleep for 30 mins... but I don't wait it to stop/interrupt the other part of the while loop from my original post.

EDIT: Testing with Excel for the meantime lol

Edited by Hyflex

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