Script to close all open windows

Get help with using AutoHotkey and its commands and hotkeys
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

Re: Script to close all open windows

09 Jun 2017, 07:08

Thouldre wrote:After closing all windows I first have to klick on the desktop before I can use Alt+F4 to shutdown Windows. Can you auto focus the desktop after closing all windows?
I just tried the script and pressing Alt+F4 to bring up the Shut Down Windows dialog box worked as it is for me, without needing to manually focus anything. Anyway, you can try adding one of the following at the end:
  • WinActivate % "ahk_id " . DllCall("GetShellWindow", "Ptr") - focuses the desktop window, which accepts Alt+F4
  • ComObjCreate("Shell.Application").ShutdownWindows - shows the Shut Down Windows dialog box automatically
Thouldre
Posts: 42
Joined: 25 May 2017, 14:29

Re: Script to close all open windows

09 Jun 2017, 07:55

I used the first one and it works! But unfortunately there is another problem: If documents are still open you are going to be asked if you want to save the current state. With the original script you would just hit "Enter" and it would save the document. But now you have to klick on each document to hit "Enter" probably because of the focus at the desktop. With CloseAll you could just hit "Enter" for each document to save the document e.g. 3 open documents: Enter, Enter, Enter and then press Alt+F4 to shutdown the system.
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

Re: Script to close all open windows

09 Jun 2017, 08:09

Off the top of my head, one of these workarounds may work:
  • Inside the loop, use WinGet to get the PID of the process hosting the window and use Process WaitClose to wait for the window to close before having the script post SC_CLOSE to the next window
  • Outside of the loop, before activating the shell window, run GetTaskbarVisibleWindows() in another loop and have the script wait before selecting the shell window. Something like this, I think:

    Code: Select all

    while (GetTaskbarVisibleWindows().MaxIndex())
    	Sleep 100
    

Return to “Ask For Help”

Who is online

Users browsing this forum: BarryGil, Bing [Bot], boiler, Google [Bot], mikeyww and 42 guests