Jump to content

Killing several windows that start with the same title - what am I doing wrong?


Akshay07
 Share

Recommended Posts

Hi all,

I want to execute a script which will check if there are any existing windows starting with the title "Stopwatch".

When I try to test it, I have several windows opened with titles

"Stopwatch - #1"

"Stopwatch - #2"

"Stopwatch - #3"

and so on.

When I run it, only one window is killed and the script never reaches the "Exit" statement. I can't see what is wrong!

I did not try WinClose, because if one of the window can be killed with WinKill, then all of them should be able to be closed in this way.

Here is the script:

While WinExists ( "Stopwatch" ) 
    WinKill ( "Stopwatch" ) 
    Sleep (200)
WEnd

Exit

EDIT: Seems it works better if I use WinActivate first (the Help did mot mention that). BUT after all windows have been closed, I still do not reach the Exit statement and the script acts like if it does a WinActivate event though no more Stopwatch windows exist (I am loosing focus on the main window again and again and again (looks like it does not exit the While-wEnd loop).

Edited by Akshay07
Link to comment
Share on other sites

The reason your script doesn't end after all the windows are closed is because it's a While loop. It won't end until you tell it to. Look into Do...Until (If I get your question).

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

The reason your script doesn't end after all the windows are closed is because it's a While loop. It won't end until you tell it to. Look into Do...Until (If I get your question).

The While condition is False when no window with a matching name exists any more, and that exits the While loop, so it should work if WinKill() succeeds in killing the last one.

@Akshay07: There could be an unintended match to a window you can't kill, or perhaps a service is restarting it. Check it out with WinList() after you think they are all gone to see.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...