确保使用 autohotkey 安装文件夹中的窗口间谍实用程序获取窗口标题和文本。
关闭窗口的方法有很多种,有时你必须用力一点。您甚至可能需要使用管理员权限运行脚本。您也不需要定义必须按下才能删除窗口的热键。您可以完全自动化整个过程。尝试一下:
#Persistent ;Ensure the script doesn't exit immediately
If not A_IsAdmin ;force the script to run as admin
{
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
;Enter the correct win title and a correct substring of the win text and maybe also the ClassNN of the button whoch closes it
windowTitle = Microsoft Visual Studio
windowText = A network-related or instance-specific error
closeButton = Button1
;Call CloseWindow periodically passing the contents of above variables as arguments:
CloseWindowWithBoundArgument := Func("CloseWindow").bind(windowTitle, windowText, closeButton)
SetTimer, %CloseWindowWithBoundArgument%
;Wait for a window to exist, then close it:
CloseWindow(winTitle,winText,buttonClassNN) {
WinWait, %winTitle%, %winText% ;wait until the window exists
;There are multiple methods to close a window:
;Close window method 1 (similar to pressing alt+F4)
PostMessage, 0x112, 0xF060,,, %winTitle%, %winText%
;Close window method 2 (sends a WM_CLOSE message; somewhat forcefully)
WinClose, %winTitle%, %winText%
;Close window method 3 (forcefully closing a window using server different methods internally)
WinKill, %winTitle%, %winText%
;Close window method 4 (clicking a button to close the window)
ControlClick, %buttonClassNN%, %winTitle%, %winText%
}