Jump to content

Winwait for a specific window name


Tr10
 Share

Recommended Posts

What I would like to accomplish is this:

I run a program that often crashes, when it does crash it will pop up with a window titled "StealthBot"

I wrote this autoit script to wait for that window title exactly.

but for some reason, it will always find the program even when its window title contains stealthbot and try to execute the commands.

Opt("WinTitleMatchMode", 3)
While Winwait ( "StealthBot" )
    sleep (1000)
    Winactivate ( "StealthBot" )
    sleep (1000)
    send ("{enter}")
    sleep (500)
    run ( "C:\Program Files\StealthBot\old\sb.exe")
    sleep (10000)
    Send ( "{alt}")
    Sleep (300)
    Send ( "s" )
    Sleep (300)
    Send ("s")
WEnd

The other window title is [eDDma, online in channel Clan GM] - Stealthbot v2.6 Revision 3

Here is a screenshot of the window I am looking for.

Posted Image

If anyone can think of a more productive way to do this, it would be fantastic.

Thank you :)

Any questions or input you have will be helpful.

Link to comment
Share on other sites

Hi! Wrong algorithm, try this:

Opt("WinTitleMatchMode", 3)

Winwait ( "StealthBot" )

While WinExists("StealthBot")
    sleep (1000)
    Winactivate ( "StealthBot" )
    sleep (1000)
    send ("{enter}")
    sleep (500)
    run("C:\Program Files\StealthBot\old\sb.exe")
    sleep (10000)
    Send ( "{alt}")
    Sleep (300)
    Send ( "s" )
    Sleep (300)
    Send ("s")
WEnd

:)

Link to comment
Share on other sites

Hi! Wrong algorithm, try this:

Opt("WinTitleMatchMode", 3)

Winwait ( "StealthBot" )

While WinExists("StealthBot")
    sleep (1000)
    Winactivate ( "StealthBot" )
    sleep (1000)
    send ("{enter}")
    sleep (500)
    run("C:\Program Files\StealthBot\old\sb.exe")
    sleep (10000)
    Send ( "{alt}")
    Sleep (300)
    Send ( "s" )
    Sleep (300)
    Send ("s")
WEnd

:)

Thanks for fixing my error :)

But for some reason, it keeps finding the other window instead of the one that reads Stealthbot.

The error box doesn't seem to have its own window, it seems that it is somehow a part of the already existing window

Link to comment
Share on other sites

I guess this would do the trick?

Opt("WinTitleMatchMode", 4)

While 1
    
    If WinExists("[TITLE:StealthBot]", "Run-time error") Then
        WinClose("[LAST]")
    EndIf
    Sleep(250)
WEnd
I will give it a try and get back to you :)

I like the angle that you approached this at, I would have never thought to do that :)

Thank you :)

Anyone else have any ideas?

Link to comment
Share on other sites

I will give it a try and get back to you :)

I like the angle that you approached this at, I would have never thought to do that :)

Thank you :)

Anyone else have any ideas?

Maybe instead of

While Winwait ( "StealthBot" )

try

While WinwaitActive ( "StealthBot" )

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I will give it a try and get back to you :)

I like the angle that you approached this at, I would have never thought to do that :)

Thank you :)

Anyone else have any ideas?

I guess you're trying to make an auto-restarter application right? So if the StealthBot app crashes, it will 'handle' the crash message, and restart it?

Link to comment
Share on other sites

Great.

It should handle all run-time errors(atleast the ones that pops up a msg box with that title and text), but for more 'critical' errors, you might need to add more 'handling'. lol

You're amazing, that worked perfectly, I assume the same script will work as long as I change the optional text it searches for?

I appreciate all the time and effort you all put into helping me with this annoying problem :)

Thanks again <3

Link to comment
Share on other sites

You're amazing, that worked perfectly, I assume the same script will work as long as I change the optional text it searches for?

I appreciate all the time and effort you all put into helping me with this annoying problem :)

Thanks again <3

Always glad to help. :)

If you wan't to catch more error messages(named otherwise) one approach would be to do like this:

Opt("WinTitleMatchMode", 4)

Dim $aErrorMessages[2][2] ; create our array that will hold our window titles and texts

; $aErrorMessages[x][0] will be window title to catch
; $aErrorMessages[x][1] will be window text to catch

$aErrorMessages[0][0] = "[TITLE:StealthBot]"    ; title of window #1
$aErrorMessages[0][1] = "Run-time error"        ; text of window  #1
$aErrorMessages[1][0] = "[TITLE:BoobBot]"       ; title of window #2 (hihi)
$aErrorMessages[1][1] = "Mega error"        ; text of window  #2

While 1
   
    For $i = 0 To UBound($aErrorMessages)-1 ; loop through the array
        If WinExists($aErrorMessages[$i][0], $aErrorMessages[$i][1]) Then ; if the window exist
            WinClose($aErrorMessages[$i][0], $aErrorMessages[$i][1]) ; close the window
            ; perhaps do something more here too? restarting it perhaps :)
        EndIf
        Sleep(250) ; sleep 250 ms to avoid killing that workhorse of yours ;P
    Next
    
WEnd
Edited by FreeFry
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...