如何使用autohotkey退出程序?

时间:2012-12-31 21:07:18

标签: google-chrome batch-file autohotkey

我正在使用autohotkey进行一些自动化过程。

关闭chrome.exe我需要帮助

我试过

        Process, Close,  chrome.exe
;    or
        Run taskkill /im chrome.exe

但是当我再次启动它时,它会让我崩溃。

由于

3 个答案:

答案 0 :(得分:6)

使用WinClose向窗口发送关闭消息,而不是终止进程:

SetTitleMatchMode 2
WinClose Google Chrome

答案 1 :(得分:0)

如果单个 Chrome窗口(通常包含多个标签)已打开,则

mihai's helpful answer效果很好。

但是,如果要关闭所有打开Chrome窗口,需要做更多工作:

%%F

另请注意,; Get all hWnds (window IDs) created by chrome.exe processes. WinGet hWnds, List, ahk_exe chrome.exe ; Loop over all hWnds and close them. Loop, %hWnds% { hWnd := % hWnds%A_Index% ; get next hWnd WinClose, ahk_id %hWnd% } 使用WinClose消息使用WM_CLOSE消息"有点强大"并建议以下PostMessage替代方案,它模仿按 Alt-F4 的用户操作或使用窗口菜单的Close项:

; Get all hWnds (window IDs) created by chrome.exe processes.
WinGet hWnds, List, ahk_exe chrome.exe

; Loop over all hWnds and close them.
Loop, %hWnds%
{
  hWnd := % hWnds%A_Index% ; get next hWnd
  PostMessage, 0x112, 0xF060,,, ahk_id %hWnd%
}

答案 2 :(得分:0)

以下是“软关闭”特定流程的功能:

CloseAllInstances( exename )
{
    WinGet LhWnd, List, % "ahk_exe " exename
    Loop, %LhWnd%
        PostMessage, 0x112, 0xF060,,, % "ahk_id " LhWnd%A_Index%
}

因此,您只需调用以下行来关闭所有chrome实例:

CloseAllInstances( "chrome.exe" )