2012-12-31 29 views
2

我使用autohotkey做一些自动化过程。如何使用autohotkey退出程序?

我需要关闭的chrome.exe

帮助我试图

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

,但它给我的崩溃铬错误,当我再次启动它。

感谢

回答

6

使用WinClose发送关闭消息窗口,而不是杀死进程:

SetTitleMatchMode 2 
WinClose Google Chrome 
0

mihai's helpful answer作品好,如果一个浏览器窗口(通常包含多个标签 ) 开了。

然而,需要更多的工作,如果你想关闭所有打开Chrome浏览器窗口

; 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消息WinClose documentation电话‘有点泼辣’并建议以下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% 
}