5
@echo off
taskkill /F /T /IM speedfan.exe
start "" "C:\Program Files (x86)\SpeedFan\speedfan.exe"
cls
exit

I use the above commands in a .bat file to restart SpeedFan automatically each time after the computer wakes up from the sleep mode.

However, the old SpeedFan icon in the system tray will not automatically disappear when the new one appears. I have to manually move the cursor to the old icon so as to make it disappear. How can I make it disappear automatically?

I just found a simple solution: download NoTrayOrphans.exe from http://www.autohotkey.net/~Nazzal/Other/NoTrayOrphans.exe

My thanks to all of you for your help!

4 Answers4

2

I had the exact same problem, and fixed it with a simple change to my bat file and without having to install any other programs.

The problem is you are running taskkill with /f wich forces (hard) kills the task. If you kill it without the /f it sends a close signal to the application, the application exits cleanly and removes its system tray icon.

In my bat file I do two taskkill commands; the first without the /f and then again with the /f. If the first one works (which it usually should) then all is well and the system tray icon goes away. If for some reason the first one fails, the the second one will still kill it, although in that case the system tray icon would not be removed.

So, in your case, use:
taskkill /T /IM speedfan.exe
taskkill /F /T /IM speedfan.exe

RBorchert
  • 121
1

Now for a proper answer.

Just use a simple AutoIt script instead of taskkill /F /IM:

 WinClose("SpeedFan")

You just need to make sure that "Minimize on close" is disabled in the SpeedFan configuration ("Options"-Tab).


I'm sorry if this is not a proper answer and I can't back it up with personal experience but have you even tried to find a solution?

My general approach would be to make virtual mouse movements or use some Windows-api calls to force windows to refresh the notification area.

I've never done something like that but after a few searches i arrived at this Google Search String: windows refresh icons "system tray" OR "notification area" autohotkey OR autoit

One good looking result: AHK - ow-to-refresh-system-tray-icons
Another one: autohotkey.com/board/topic/80624-notrayorphans/ (linked in the thread from above)

Other results (without autohotkey OR autoit):

  1. refreshing-the-notification-area-system-tray
  2. forum.lazarus.freepascal.org/index.php?topic=14847.0
  3. blog.stephenklancher.com/2013/08/refreshing-the-notification-area-system-tray/ (with executable - but it doesn't seem to work on windows 8.1 with classic-shell)

There is a Possible Duplicate on SO (i remember seeing more but i can't seem to find them): stackoverflow.com/questions/74723/can-you-send-a-signal-to-windows-explorer-to-make-it-refresh-the-systray-icons

Unfortunately i can't post more direct links and i would have preferred to write a comment instead of this 'answer'...

Limer
  • 471
0

Place the code below in your batch file to refresh the systray. found a source at this link that works well (code pasted below from link)

@echo off
reg export "HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" %userprofile%\desktop\traynotify.reg /y
reg delete "HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" /v IconStreams /f
reg delete "HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" /v PastIconsStream /f
taskkill /f /im explorer.exe
start explorer.exe
exit
0

The following batch will move the curer over the icons and the ones from programs that have exited will be removed:

Look at https://www.nirsoft.net/utils/nircmd.html for free functions.

SET "_NirCmd=D:\_NirSoft\nircmd-x64\nircmd.exe"

:: For the Taskbar on the bottom scan left -> right<br/> %_NirCmd% SETCURSOR 1445, 1060<br/> FOR /L %%C in (1,1,20) DO %_NirCmd% MOVECURSOR 20, 0<br/> %_NirCmd% SETCURSOR 1445, 1060 <=== Just to move out of the way

:: For the Taskbar on the right scan two columns top -> down %_NirCmd% SETCURSOR 1895, 800<br/> FOR /L %%C in (1,1,20) DO %_NirCmd% MOVECURSOR 0, 10<br/> %_NirCmd% SETCURSOR 1870, 800<br/> FOR /L %%C in (1,1,20) DO %_NirCmd% MOVECURSOR 0, 10<br/> %_NirCmd% SETCURSOR 1895, 800 <=== Just to move out of the way

DarkDiamond
  • 1,919
  • 11
  • 15
  • 21