How to close a specific program from the system tray?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
yfjuu6
Posts: 118
Joined: 28 Apr 2023, 15:28

How to close a specific program from the system tray?

Post by yfjuu6 » 07 Jun 2023, 15:13

I have a specific program that is running in the system tray icon ("ahk_exe QTranslate.exe"), I want it to be closed automatically from the system tray icon if it is running whenever I open another specific program ("ahk_exe phpstorm64.exe").

l've tried this, But this closes only the window of ("QTranslate") If it is exist, And It still running in the system tray :

Code: Select all

    
    loop{
        WinWaitActive, ahk_exe phpstorm64.exe
        if WinExist("ahk_exe QTranslate.exe")
        {
            WinKill, ahk_exe QTranslate.exe
        }
    }
- Is there any script to close the specified program from the system?

- Please help! I appreciate your time and effort. Thanks in advance.

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: How to close a specific program from the system tray?

Post by mikeyww » 07 Jun 2023, 18:46

Hello,

If the program has a command-line option to exit, that is often a good way to go. Another approach is to see if WinClose works when DetectHiddenWindows is set. If not, the Process command typically works.

User avatar
yfjuu6
Posts: 118
Joined: 28 Apr 2023, 15:28

Re: How to close a specific program from the system tray?

Post by yfjuu6 » 07 Jun 2023, 19:09

mikeyww wrote:
07 Jun 2023, 18:46
Hello,

If the program has a command-line option to exit, that is often a good way to go. Another approach is to see if WinClose works when DetectHiddenWindows is set. If not, the Process command typically works.
I've got this solution, It's working great :
- It would be nice to rerun "ahk_exe QTranslate.exe" automatically after closing the "ahk_exe phpstorm64.ex".
Could you Add something to this script or another to do that? Thanks.

- This is the file path : "C:\Program Files (x86)\QTranslate\QTranslate.exe"

Code: Select all

CloseQTranslate("ahk_exe phpstorm64.exe")
Exit ; End of auto-execute

CloseQTranslate(WinTitle) {
    fn := Func("CloseQTranslate_Timer").Bind(WinTitle)
    SetTimer % fn, -1
}

CloseQTranslate_Timer(WinTitle) {
    WinWait, % WinTitle
    prev := A_DetectHiddenWindows
    DetectHiddenWindows On
    WinClose ahk_class QTranslate_ApplicationWindow
    DetectHiddenWindows % prev
    WinWait ahk_exe QTranslate.exe
    SetTimer , , -1
}


Post Reply

Return to “Ask for Help (v1)”