Jump to content
Sign in to follow this  
Docfxit

How to check for a windows presents and continue if it's not there

Recommended Posts

Docfxit

I have a script that I would like to find out how to check to see if a window is on the screen. If it is on the screen I'd like to send an enter key. If it's not on the screen I'd like to conginue with the loop it's in.

Below you will see the window I'd like to find out how to check for.

Thank you,

Docfxit

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseAnsi=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Dim $t
Dim $Crashed = -1
Dim $Show_Log
HotKeySet("{F9}", "Terminate")
HotKeySet("{F10}", "Show_Log")

MsgBox(0, "K9 Restarter", "Running K9 and minimizing..." & @CRLF & "")
Start_K9()

While 1
    $t = $t + 1
    If $t = 5 Then
        Start_K9()
        $t = 0
    EndIf
                ;********    If this window is on the screen send Enter to close it   ***********
                ;                  If it isn't on the screen don't wait for it.  continue with the loop.
        ;WinWait("K9 - 1.28 - http://keir.net","Something bad happen")
        ;If Not WinActive("K9 - 1.28 - http://keir.net","Something bad happen") Then WinActivate("K9 - 1.28 - http://keir.net","Something bad happen")  
        ;WinWaitActive("K9 - 1.28 - http://keir.net","Something bad happen")
        ;Send("{ENTER}")
    Sleep(1000)
WEnd

Func Start_K9()
    If Not ProcessExists ("K9.exe") Then
    Run("C:\Program Files\K9\K9.exe", "", @SW_MINIMIZE)
    $Crashed = $Crashed + 1
    EndIf
    Sleep(1000)
EndFunc
    
Func Terminate()
    Exit 0
EndFunc

Func Show_Log()
    $Show_Log = Not $Show_Log
    If ($Show_Log) Then
        If (ProcessExists ("K9.exe")) Then
            SplashTextOn("K9 Restarter","K9 is running." & @CRLF & "K9 has crashed " & $Crashed & " times.",300,75,0,0)
        Else
            SplashTextOn("K9 Restarter","K9 is NOT running." & @CRLF & "K9 has crashed " & $Crashed & " times.",300,75,0,0)
        EndIf
    Else
        SplashOff()
    EndIf
EndFunc
Edited by docfxit

Share this post


Link to post
Share on other sites
herewasplato

maybe

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseAnsi=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Dim $t
Dim $Crashed = -1
Dim $Show_Log
HotKeySet("{F9}", "Terminate")
HotKeySet("{F10}", "Show_Log")

MsgBox(0, "K9 Restarter", "Running K9 and minimizing..." & @CRLF & "")
Call("Start_K9")

While 1
    $t = $t + 1
    If $t = 5 Then
        Call("Start_K9")
        $t = 0
    EndIf

    If WinExists("K9 - 1.28 - [url="http://keir.net"]http://keir.net[/url]", "Something bad happen") Then
        WinActivate("K9 - 1.28 - [url="http://keir.net"]http://keir.net[/url]", "Something bad happen")
        WinWaitActive("K9 - 1.28 - [url="http://keir.net"]http://keir.net[/url]", "Something bad happen")
        Send("{ENTER}")
    EndIf
 
    Sleep(1000)
WEnd

Func Start_K9()
    If Not ProcessExists("K9.exe") Then
        Run("C:\Program Files\K9\K9.exe", "", @SW_MINIMIZE)
        $Crashed = $Crashed + 1
    EndIf
    Sleep(1000)
EndFunc   ;==>Start_K9

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


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Docfxit

maybe

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseAnsi=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Dim $t
Dim $Crashed = -1
Dim $Show_Log
HotKeySet("{F9}", "Terminate")
HotKeySet("{F10}", "Show_Log")

MsgBox(0, "K9 Restarter", "Running K9 and minimizing..." & @CRLF & "")
Start_K9()

While 1
    $t = $t + 1
    If $t = 5 Then
        Start_K9()
        $t = 0
    EndIf

    If WinExists("K9 - 1.28 - [url="http://keir.net"]http://keir.net[/url]", "Something bad happen") Then
        WinActivate("K9 - 1.28 - [url="http://keir.net"]http://keir.net[/url]", "Something bad happen")
        WinWaitActive("K9 - 1.28 - [url="http://keir.net"]http://keir.net[/url]", "Something bad happen")
        Send("{ENTER}")
    EndIf
 
    Sleep(1000)
WEnd

Func Start_K9()
    If Not ProcessExists("K9.exe") Then
        Run("C:\Program Files\K9\K9.exe", "", @SW_MINIMIZE)
        $Crashed = $Crashed + 1
    EndIf
    Sleep(1000)
EndFunc   ;==>Start_K9

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate
That is working perfectly. Thank you very much.

This seems to be working really great to keep K9 running. I wish it was as easy to find the networking error in FreePops that is causing K9 to crash.

Thank you,

Docfxit

Edited by docfxit

Share this post


Link to post
Share on other sites
Docfxit

This was working. I can't figure out what I did but it isn't working any more. It's not recognizing the window being open.

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number
Dim $t
Dim $Crashed = -1
Dim $Show_Log
HotKeySet("{F8}", "Terminate")
HotKeySet("{F10}", "Show_Log")

MsgBox(0, "K9 Restarter", "Running K9 and minimizing..." & @CRLF & "")
Start_K9()

While 1
    $t = $t + 1
    If $t = 5 Then
        Call("Start_K9")
        $t = 0
    EndIf
; *****   It doesn't recognize this window  *****
    If WinExists("K9 - 1.28 - http://keir.net", "Something bad happen") Then
        WinActivate("K9 - 1.28 - http://keir.net", "Something bad happen")
        WinWaitActive("K9 - 1.28 - http://keir.net", "Something bad happen")
        Send("{ENTER}")
        EndIf
; *****   It doesn't recognize this window  *****
    If WinExists("K9", "This program has performed") Then
        WinActivate("K9", "This program has performed")
        WinWaitActive("K9", "This program has performed")
        Send("{ENTER}")
        EndIf
    Sleep(8000)
WEnd

Func Start_K9()
    If Not ProcessExists ("K9.exe") Then
    Run("C:\Program Files\K9\K9.exe", "", @SW_MINIMIZE)
    $Crashed = $Crashed + 1
    EndIf
    Sleep(1000)
EndFunc
    
Func Terminate()
    Exit 0
EndFunc

Func Show_Log()
    $Show_Log = Not $Show_Log
    If ($Show_Log) Then
        If (ProcessExists ("K9.exe")) Then
            SplashTextOn("K9 Restarter","K9 is running." & @CRLF & "K9 has crashed " & $Crashed & " times.",300,75,0,0)
        Else
            SplashTextOn("K9 Restarter","K9 is NOT running." & @CRLF & "K9 has crashed " & $Crashed & " times.",300,75,0,0)
        EndIf
    Else
        SplashOff()
    EndIf
EndFunc

I can't figure it out for the life of me.

Thank you,

Docfxit

Edited by docfxit

Share this post


Link to post
Share on other sites
Docfxit

I figured out what is happening but I don't know how to solve it.

When the window "Something bad happen" pops up this script locks up and doesn't continue running.

What would cause this script to lock up. It was running fine and catching the window "Something bad happen" at one point.

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number
Dim $t
Dim $Crashed = -1
Dim $Show_Log
HotKeySet("{F8}", "Terminate")
HotKeySet("{F10}", "Show_Log")

MsgBox(0, "K9 Restarter", "Running K9 and minimizing..." & @CRLF & "")
Start_K9()

While 1
    $t = $t + 1
    If $t = 5 Then
        Start_K9()
        $t = 0
    EndIf

;  I added the following 9 lines to see what windows were being recognized
$var = WinList()
    For $i = 1 to $var[0][0]
    ; Only display visble windows that have a title
        If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
            $text = WinGetText($var[$i][0], "")
;  ******  When the window "Something bad happen" pops up this script locks up on the next line
            MsgBox(0, "Details", "Title= " & $var[$i][0]  & @LF & "Text= " & $text & @LF & "Handle= " & $var[$i][1])
        EndIf
    Next
    If WinExists("K9 - 1.28 - http://keir.net", "Something bad happen") Then
        WinActivate("K9 - 1.28 - http://keir.net", "Something bad happen")
        WinWaitActive("K9 - 1.28 - http://keir.net", "Something bad happen")
        Send("{ENTER}")
        EndIf
    If WinExists("K9", "This program has performed") Then
        WinActivate("K9", "This program has performed")
        WinWaitActive("K9", "This program has performed")
        Send("{ENTER}")
        EndIf
    Sleep(8000)
WEnd

Func Start_K9()
    If Not ProcessExists ("K9.exe") Then
    Run("C:\Program Files\K9\K9.exe", "", @SW_MINIMIZE)
    $Crashed = $Crashed + 1
    EndIf
    Sleep(1000)
EndFunc
 Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

Func Terminate()
    Exit 0
EndFunc

Func Show_Log()
    $Show_Log = Not $Show_Log
    If ($Show_Log) Then
        If (ProcessExists ("K9.exe")) Then
            SplashTextOn("K9 Restarter","K9 is running." & @CRLF & "K9 has crashed " & $Crashed & " times.",300,75,0,0)
        Else
            SplashTextOn("K9 Restarter","K9 is NOT running." & @CRLF & "K9 has crashed " & $Crashed & " times.",300,75,0,0)
        EndIf

    Else
        SplashOff()
    EndIf
EndFunc

I can't figure it out for the life of me.

Thank you,

Docfxit

Share this post


Link to post
Share on other sites
herewasplato

... What would cause this script to lock up. ...

In this post your code had this directive:

#AutoIt3Wrapper_UseAnsi=y

What operating system are you running this code on?

What version of Autoit are you running this code with?

Also, when you say that the script locks up - does it display the MsgBox behind the window that K9 has put up? Is there any indication of a MsgBox in the taskbar? (I've seen a MsgBox only show up there.)

Details....


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Docfxit

Thank you for the reply...

In this post your code had this directive:

#AutoIt3Wrapper_UseAnsi=y

Yes it did. I tried running it without that in order to troubleshoot the problem. Do I need it?

What operating system are you running this code on?

I'm trying to get it to run in '98. I have also been testing in XP Pro just to try to figure out if it's a problem with '98.

What version of Autoit are you running this code with?

3.2.12.1 on both '98 and XP

Also, when you say that the script locks up - does it display the MsgBox behind the window that K9 has put up? Is there any indication of a MsgBox in the taskbar? (I've seen a MsgBox only show up there.)

Details....

No. There is no Msgbox behind any window or on the taskbar.

Do you have any ideas for me to test with?

Thank you,

Docfxit

Share this post


Link to post
Share on other sites
herewasplato

Thank you for the reply...

You are welcome - but I'm not sure I'm helping much.

I like to get the details posted in the hopes that someone will stop by and post a solution for you.

You need the directive (#AutoIt3Wrapper_UseAnsi=y) for W98 - so leave it there.

Add this directive and run the code from SciTE without compiling

#AutoIt3Wrapper_Run_Debug_Mode=Y

Are you using W98 or W98SE?

If I install D9 on my W98SE Virtual Machine, how do I crash it like you are seeing?


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Docfxit

Thank you for the reply...

You are welcome - but I'm not sure I'm helping much.

Any suggestions at all at this moment might lead to fixing the problem. All are appreciated.

I like to get the details posted in the hopes that someone will stop by and post a solution for you.

You need the directive (#AutoIt3Wrapper_UseAnsi=y) for W98 - so leave it there.

Add this directive and run the code from SciTE without compiling

#AutoIt3Wrapper_Run_Debug_Mode=Y

Where is the output from the debug? Is there someplace I can read about it?

Are you using W98 or W98SE?

I'm running W98SE. This same problem happens in XP Pro so I don't think you have to run it in W98SE if XP is more convenient.

If I install K9 on my W98SE Virtual Machine, how do I crash it like you are seeing?

I don't know how exacting you have to be to my configuration but I'll let you know how I have it setup.

Overview:

I am downloading email from Yahoo POP3 (not the paid version) through K9 (as a spam filter) into Pegasus Email.

Details:

To download Yahoo POP3 I am using

FreePOPs with the Yahoo module.

You can get FreePOPs at: http://sourceforge.net/project/showfiles.p...ckage_id=116973

This one will install it for you: http://downloads.sourceforge.net/freepops/...mp;big_mirror=0

With FreePOPs you will need to run the updater . It's in the start menu under FreePOPs, FreePOPs Updater. It will update a few modules.

With FreePOPs you will need to download the latest Yahoo module. Yahoo BETA - 0.2.1f

You can get it here: http://www.diludovico.org/forum/showthread.php?t=7541

It's the first post. Download the zip file, Unzip it and put it in the folder: C:\Program Files\FreePOPs\LUA (the folder should be on your machine already)

K9 can be downloaded at: http://www.keir.net/k9.html

Download the exe file and install it.

I don't remember what (If any) configuration changes I made. So if you have any problem running it let me know and I'll go over the settings with you.

I'm using Pegasus Email. I'm guessing you can use any Email client since the problem happens with K9.

I use Pegasus because It isn't susceptible to viruses and the configuration allows me to do lots of nice things.

If you feel like using Pegasus Email you can download it here: http://www.5star-shareware.com/Windows/Int...EC/pegasus.html

Click on the File Size and it will download.

There are lots of configuration options to make it run and look like anything you want.

During the installation it will ask you for your ISP information. It isn't mandatory you put it in during install but it can be easier through the wizard.

The server host name will be: 127.0.0.1

The user name will be: Localhost/2000/UserName@yahoo.com

You will need to replace UserName with any Yahoo user name. If you like you can PM me and I'll give you mine.

If you use mine all you need to configure is Do not put a check mark in "Delete mail on server once it has been successfully received"

In password you will need the password of the Yahoo account.

In Server TCP/IP port you will need to put 9999

You might have to increase the timeout because Yahoo is slow. Mine is set at 1220.

If you have any problems let me know and I'll explain more settings. I think that might get you started for a test. If you were to run Pegasus regularly there are other settings that make it much nicer to use.

Then I run the AutoIt script to restart K9 when it crashes. Currently the script looks like this:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
;  This is for '98
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Run_Debug_Mode=Y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number
Dim $t
Dim $Crashed = -1
Dim $Show_Log
HotKeySet("{F8}", "Terminate")
HotKeySet("{F10}", "Show_Log")

Start_K9()
MsgBox(0, "K9 Restarter", "Running K9 and minimizing..." & @CRLF & "")

While 1
    $t = $t + 1
    If $t = 5 Then
        Start_K9()
        $t = 0
    EndIf

$var = WinList()

    For $i = 1 to $var[0][0]
    ; Only display visble windows that have a title
        If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
            $text = WinGetText($var[$i][0], "")
;  ******  When the window "Something bad happen" pops up this script locks up on the next line
            MsgBox(0, "Details", "Title= " & $var[$i][0]  & @LF & "Text= " & $text & @LF & "Handle= " & $var[$i][1])
        EndIf
    Next
    If WinExists("K9 - 1.28 - http://keir.net", "Something bad happen") Then
        WinActivate("K9 - 1.28 - http://keir.net", "Something bad happen")
        WinWaitActive("K9 - 1.28 - http://keir.net", "Something bad happen")
        Send("{ENTER}")
        EndIf
    If WinExists("K9", "This program has performed") Then
        WinActivate("K9", "This program has performed")
        WinWaitActive("K9", "This program has performed")
        Send("{ENTER}")
        EndIf
    Sleep(8000)
WEnd

Func Start_K9()
    If Not ProcessExists ("K9.exe") Then
    Run("C:\Program Files\K9\K9.exe", "", @SW_MINIMIZE)
    $Crashed = $Crashed + 1
    EndIf
    Sleep(1000)
EndFunc
 Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

Func Terminate()
    Exit 0
EndFunc

Func Show_Log()
    $Show_Log = Not $Show_Log
    If ($Show_Log) Then
        If (ProcessExists ("K9.exe")) Then
            SplashTextOn("K9 Restarter","K9 is running." & @CRLF & "K9 has crashed " & $Crashed & " times.",300,75,0,0)
        Else
            SplashTextOn("K9 Restarter","K9 is NOT running." & @CRLF & "K9 has crashed " & $Crashed & " times.",300,75,0,0)
        EndIf

    Else
        SplashOff()
    EndIf
EndFunc

There is a lot of setup involved to reproduce this error. I certainly wouldn't blame you if you didn't want to go through the effort.

Thank you for your interest in helping to find this problem.

The current line numbers won't be displayed when this is compiled so you will need to run this interactively. I think it's a bug in the compiler.

Thank you for looking at it.

Docfxit

Edited by docfxit

Share this post


Link to post
Share on other sites
herewasplato

... Where is the output from the debug? Is there someplace I can read about it? ...

The output window is in the lower part of the SciTE app. You might need the full version of SciTE4AutoIt3 for the output pane to work/show - I'm not sure. Be sure to run your without compiling it. Hit F8 to show the output pane and then F5 to run your code.

I'm not even sure that it will tell you much - but it could not hurt at this point.

This code...

#AutoIt3Wrapper_Run_Debug_Mode=Y
MsgBox(0, "", "")
... produces this output:

>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "c:\Temp\SciTE-temp.au3"

!> Starting in DebugMode..

Line: @error-@extended: Line syntax

0001: 0-0: #AutoIt3Wrapper_Run_Debug_Mode=Y

0002: 0-0: MsgBox(0, "", "")

+>20:02:40 AutoIT3.exe ended.rc:0

I'll see what I can do on duplicating your setup in a VM and I have a yahoo account. :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Docfxit

I discovered what is causing this script to not recognize the window:

If WinExists("K9 - 1.28 - http://keir.net", "Something bad happen") Then

WinActivate("K9 - 1.28 - http://keir.net", "Something bad happen")

WinWaitActive("K9 - 1.28 - http://keir.net", "Something bad happen")

Send("{ENTER}")

EndIf

When these are commented out it recognizes the above window.

HotKeySet("{F9}", "Terminate")

HotKeySet("{F10}", "Show_Log")

Why would that be?

Thank you,

Gary Kuznitz

Share this post


Link to post
Share on other sites
BrettF

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.