AutoIT关闭除关机以外的所有窗口

时间:2017-07-05 10:31:02

标签: windows autoit

我正在构建一个程序,使用AutoIT和我在此处找到的代码在没有鼠标移动60秒后关闭所有打开的窗口: https://www.autoitscript.com/forum/topic/97638-closing-all-open-windows/

我编辑了一下它看起来像这样:

#include <MsgBoxConstants.au3>
Opt("WinTitleMatchMode", 3) ;3 = exact title match
Opt("TrayIconDebug", 1)

$S_running = "check-4-app2" ;name the script
If WinExists($S_running) Then Exit

AutoItWinSetTitle($S_running)

$count = 0
$mousePos = MouseGetPos()
while 1
   $count += 1
   $mousePosNow = mouseGetPos()

   If $mousePosNow[0] <> $mousePos[0] Or $mousePosNow[1] <> $mousePos[1] Then $count = 0

   $mousePos = MouseGetPos()

   ;ToolTip("count = " & $count, 0, 0)

   If $count > 60 Then
      $count = 0
      $var = WinList ()
      $length = UBound($var) - 2
      For $i = 1 to $length
         If BitAnd (WinGetState ($var[$i][1]), 2) And $var[$i][0] <> "" AND $var[$i][0] <> "Program Manager" Then WinClose ($var[$i][1], "")
         Next
   EndIf
   Sleep(1000)
WEnd

它实际上会在60秒后关闭所有打开的窗口,但它也会在Windows 7中打开窗口关闭窗口(就像你按下alt + f4组合一样)。

如何阻止此窗口弹出?我只是喜欢关闭所有窗口并拥有干净的桌面视图。

1 个答案:

答案 0 :(得分:0)

首先,您应该对$ var = WinList()中的所有值进行一些调试,以查看操作系统中的某个窗口是否特殊,这意味着,如果此类窗口关闭,它将触发Windows关闭,如果问题仍然存在,我找到了一个walkround方式,我试着在我的电脑上做以下代码

WinClose("Close Windows")
; or maybe WinClose("Shutdown Windows")

关闭你所说的&#34; windows关闭窗口&#34;,也许你可以将这一行放在代码的底部

注意:在我的电脑中,它的OS语言不是英文,所以也许你应该首先触发&#34; windows shutdown window&#34;并使用AutoIt窗口信息工具精确查看其窗口标题

相关问题