Jump to content

Closing all open windows


Recommended Posts

Ok - I have looked around on the forum, but havent really seen an answer to this.

I am looking for a command to close all stray windows that are open when completing my script. About 10% of the time, a window is left open (that doesnt have a predictable header or name associated with it), and the script won't run the next time with this window open.

Any thoughts? I am sure this is super simple, but I am just starting out! Any thoughts would be helpful.

Link to comment
Share on other sites

Ok - I have looked around on the forum, but havent really seen an answer to this.

I am looking for a command to close all stray windows that are open when completing my script. About 10% of the time, a window is left open (that doesnt have a predictable header or name associated with it), and the script won't run the next time with this window open.

Any thoughts? I am sure this is super simple, but I am just starting out! Any thoughts would be helpful.

GUIDelete()?
Link to comment
Share on other sites

GUIDelete()?

I think he was looking for a way to close non-autoit windows... If so, here is the solution

$var = WinList ()
For $i = 1 to $var[0][0]
  If BitAnd (WinGetState ($var[$i][1]), 2) And $var[$i][0] <> "" Then WinClose ($var[$i][1], "")
Next

adapted to purpose from the autoit helpfile example for winlist.

MDiesel

Link to comment
Share on other sites

Thank you for the quick reply! You are exactly correct, I am wanting to close Explorer windows that remain. I have implemented the code (thank you) but it seems to want to restart (the shutdown dialog box pops up at the end of the script). Is there a way to avoid this?

Thx!

I think he was looking for a way to close non-autoit windows... If so, here is the solution

$var = WinList ()
For $i = 1 to $var[0][0]
  If BitAnd (WinGetState ($var[$i][1]), 2) And $var[$i][0] <> "" Then WinClose ($var[$i][1], "")
Next

adapted to purpose from the autoit helpfile example for winlist.

MDiesel

Link to comment
Share on other sites

$var = WinList ()
For $i = 1 to $var[0][0]
  If BitAnd (WinGetState ($var[$i][1]), 2) And $var[$i][0] <> "" And $var[$i][0] <> "Program Manager" Then WinClose ($var[$i][1], "")
Next

stab in the dark. I'm picking up a "Program Manager" window, without any open, so maybe its a background process, that is set to prompt for sutdown on close?

I haven't tried it yet, I have a lot of important and unsaved windows open at the mo.

MDiesel

Link to comment
Share on other sites

Thank you for the quick reply! You are exactly correct, I am wanting to close Explorer windows that remain. I have implemented the code (thank you) but it seems to want to restart (the shutdown dialog box pops up at the end of the script). Is there a way to avoid this?

Thx!

Probably Program Manager is in the $var array, so remove it or don't execute WinClose on it.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Ok- So I have run this a bit more, and I think I figured out what is going on. At the end of my process, I shut down a website. When I do this, about 10% I get a dialog box with a header of "Windows Internet Explorer" saying: "The webpage you are viewing is trying to close the window. Do you want to close the window?"

I can't get rid of this window, and it pops up in random places and times. I have tried the code you suggested, also WinClose("Windows Internet Explorer")

to no avail.

Probably Program Manager is in the $var array, so remove it or don't execute WinClose on it.

Link to comment
Share on other sites

Have you tried replacing winclose with WinKill??

The difference between this function and WinClose is that WinKill will forcibly terminate the window if it doesn't close quickly enough. Consequently, a user might not have time to respond to dialogs prompting the user to save data. Although WinKill can work on both minimized and hidden windows, some windows (notably explorer windows) can only be terminated using WinClose.

MDesel

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...