How the program handles the button is up to the program.. so yes, changing the settings within the app is the play. You could create a batch script that taskkills the process but that's messy Answer from Katur on reddit.com
🌐
Stack Overflow
stackoverflow.com › questions › 41739894 › c-sharp-close-any-application-running-in-system-tray
C# Close any application running in System Tray - Stack Overflow
You can even write Forms application that does not respond to [Alt F4] to shut it down. The only way you can an arbitrary process of which you know nothing (other than that it has put an icon into the system tray), is to terminate the process.
🌐
InformIT
informit.com › articles › article.aspx
Exiting a Program | Running Programs | InformIT
Figure 3.16 Right-click a system tray icon to open its shortcut menu, and then look for a command that shuts it down. However, you might occasionally need to exit or disable one of them for some special reason. For example, some installation programs will not run unless you disable virus protection ...
🌐
Chron.com
smallbusiness.chron.com › rid-tray-apps-startup-64027.html
How to Get Rid of Tray Apps at Startup
November 22, 2017 - This label helps identify the program's name. You can right-click an icon and select "Exit" or "Close" to remove the app, but it will reappear the next time you reboot your system.
🌐
AutoHotkey
autohotkey.com › board › topic › 7071-how-do-i-close-an-app-residing-in-system-tray
How do I close an App residing in System Tray - Ask for Help - AutoHotkey Community
4 weeks ago - SetKeyDelay,10 WinShow,ahk_class ZAFrameWnd WinActivate,ahk_class ZAFrameWnd WinWaitActive,ahk_class ZAFrameWnd,,0 if errorlevel != 1 { Send, !{Space} Send SS Send {Enter 2} } PS: ZoneAlarm is a persistent tray app. I have to repeat EndTask for over 7 times to kill it with CTRL+ALT+DEL. The close button will only minimize it to the System Tray.
🌐
Real.com
customer.real.com › hc › en-us › articles › 204039463-Close-programs-running-in-the-background-in-Windows
Close programs running in the background in Windows – SUPPORT
It can also help you determine ... background programs (short version). Right-click the program's icon in the system tray (next to the clock), and choose Close, Exit, or Disable....
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 16042763 › gracefully-shutting-down-system-tray-application
c# - Gracefully shutting down system tray application - Stack Overflow
If I force close it with taskkill ... end the process from a separate process? ... You need to tell your application to exit, so it can un-register from the systemtray....
🌐
eM Client
forum.emclient.com › frequently asked questions
Close app with Close application to tray - Frequently Asked Questions - eM Client
March 14, 2023 - Currently, with the option “Close application to tray” enabled, the only way I found is via tray icon’s context menu. I’d like to be able to close the app via Menu > Exit as well (so basically the option will apply only to window’s Close button and Alt+F4).
🌐
AutoHotkey
autohotkey.com › boards › viewtopic.php
How to close a specific program from the system tray? - AutoHotkey Community
June 7, 2023 - 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" ... 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 }
🌐
Andyrathbone
andyrathbone.com › 2011 › 02 › 07 › how-do-i-close-all-currently-running-programs
Andy Rathbone » How do I close all currently running programs?
February 7, 2011 - Hover your mouse over the program icons living in your System Tray. As the mouse hovers over a program’s icon, that program’s name appears in a pop-up window. When you spot your antivirus program’s icon, right-click it. When the pop-up menu appears, look for an option to disable or close ...
🌐
Reddit
reddit.com › r/autohotkey › how to close a specific program from the system tray ?
r/AutoHotkey on Reddit: How to close a specific program from the system tray ?
June 7, 2023 -

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 :

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.

Top answer
1 of 4
3

Unfortunately, there's not much you can do to gracefully terminate an application that is not cooperating.

The suggested approach is to send the WM_CLOSE message to the window(s) of interest; this won't work here since the app chooses to hide itself as you describe. However, this is the only approach that Microsoft endorses.

The next step is to be a bit more heavy-handed and send the WM_QUIT message to a thread. This is a bit problematic because you have to find the thread in question using some form of process/thread enumeration and PInvoke PostThreadMessage to post WM_QUIT. However, MSDN seems to suggest that you should not do this (search for WM_QUIT). As a practical matter, it should work though.

If that doesn't work as well then Process.Kill is all you 're left with.

Update: The above is my own understanding, but there's also a Microsoft KB article on this same subject. It works with Win32 (not managed code), but the ideas can be adapted without much trouble.

2 of 4
1

The EventWaitHandle object in a BackgroundWorker solution provided here worked pretty good for me, and I think it's easier to code than using win API messages.

Basically you got a backgroundworker thread waiting for certain named event to happen with the myEventWaitHandle.WaitOne method.

Another application just creates the same named event and call myEventWaitHandle.Set() to trigger it. This cause the WaitOne() method in the background-worker to continue and therefore the RunWorkerCompleted to be triggered. At that point you can safely close your application.

Your main application:

private void evtBgWorker_DoWork(object sender, DoWorkEventArgs e) { 
   string evtName = "MyExitRequest" + Process.GetCurrentProcess().Id.ToString(); 
   EventWaitHandle evt = new EventWaitHandle(false, EventResetMode.ManualReset, evtName); 
   evt.WaitOne(); // the worker stops here until the event is triggered
 } 

private void evtBgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 
  this.Close(); 
} 

Your "graceful killer" application:

private void CloseMainApp() 
{
   Process[] processes = Process.GetProcessesByName("MyProcessName");
   Process myprocess= null;
   if (processes.Length > 0)
   {
      myprocess = processes[0];
      string evtName = "MyExitRequest" + myprocess.Id; // the same event name
      EventWaitHandle evt = new EventWaitHandle(false, EventResetMode.ManualReset, evtName);
      evt.Set(); // triggers the event at the main app

      if (!myprocess.WaitForExit(10000)) // waits until the process ends gracefuly
      {
         // if don't...
         myprocess.Kill();
      }
   }
}
🌐
Windows 10 Forums
tenforums.com › general-support › 174826-how-do-i-remove-icons-system-tray-without-closing-app.html
How do I remove icons from the system tray? (without closing app) - Windows 10 Help Forums
February 23, 2021 - Denis Winaero has a thread showing you how to edit regedit to close the whole systray: How to Hide Notification Area in Windows 10 (System Tray) but unsure if it is in the app itself. Regardless thank you for the suggestion, was a good start. ... You can hide the whole notification area if it annoys you: You can use Policy Plus (free) on Home- or there will be an equivalent registry key or setting. Couldn't get this program to work but winaero had the full close feature.