Answers:
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
If NOT IsWindow(WinExist("ahk_id" . this_ID))
continue
WinClose, ahk_id %this_ID%
break
}
return
; This checks if a window is, in fact a window.
; As opposed to the desktop or a menu, etc.
IsWindow(hwnd){
WinGet, s, Style, ahk_id %hwnd%
return s & 0xC00000 ? (s & 0x100 ? 0 : 1) : 0
}
只需编写一个发送Alt-F4的单行脚本即可。但我假设您要关机吗?为什么不使用Shutdown命令-DOC:https://autohotkey.com/docs/commands/Shutdown.htm
您也可以使用以下常规关机命令:https://stackoverflow.com/questions/162304/how-do-i-shutdown-restart-logoff-windows-via-a-bat-file