I am using autohotkey to do some automate process.
I need help with closing chrome.exe
I tried
Process, Close, chrome.exe
; or
Run taskkill /im chrome.exe
but it give me chrome crashed error when I start it again.
Thanks
I am using autohotkey to do some automate process.
I need help with closing chrome.exe
I tried
Process, Close, chrome.exe
; or
Run taskkill /im chrome.exe
but it give me chrome crashed error when I start it again.
Thanks
Use WinClose
to send a close message to the window, rather than killing the process:
SetTitleMatchMode 2
WinClose Google Chrome
mihai's helpful answer works well if a single Chrome window (typically containing multiple tabs) is open.
However, more work is needed if you want to close all open Chrome windows:
; 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%
}
Also note that the WinClose
documentation calls using WinClose
's use of the WM_CLOSE
message "somewhat forceful" and suggests the following PostMessage
alternative, which mimics the user action of pressing Alt-F4 or using the Window menu's Close
item:
; 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%
}
Here is a function for 'soft closing' specific processes:
CloseAllInstances( exename )
{
WinGet LhWnd, List, % "ahk_exe " exename
Loop, %LhWnd%
PostMessage, 0x112, 0xF060,,, % "ahk_id " LhWnd%A_Index%
}
So you simply need to call the following line to close all chrome instances:
CloseAllInstances( "chrome.exe" )