2012-12-31 27 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% 
}