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!

Matthew Wai
  • 541
  • 3
  • 12
  • 32
  • killing and restarting explorer.exe will accomplish what you want. – Ramhound Oct 15 '15 at 13:22
  • Do you mean C:\Windows\explorer.exe? – Matthew Wai Oct 15 '15 at 13:24
  • There is only one explorer.exe on your system. – Ramhound Oct 15 '15 at 13:26
  • You can't. A program can only automatically remove its system tray icon if you shut it down cleanly. By forcing an exit via taskkill you are deliberately preventing the application having any opportunity to remove it. – qasdfdsaq Oct 15 '15 at 14:42
  • `taskkill /F /T /IM explorer.exe` `start "" "C:\Windows\explorer.exe"` explorer.exe does not start after being killed at my end. – Matthew Wai Oct 16 '15 at 00:13
  • Your NoTrayOrphans link is broken. I assume this is the same thing: https://autohotkey.com/board/topic/80624-notrayorphans/ – MarredCheese Oct 05 '18 at 22:17
  • @qasdfdsaq, you can remove dead icons by hovering the mouse over them. Matthew is looking for a way to automatically move the mouse over the SpeedFan icon so that Explorer removes it. (There's no practical way to do that, but it is possible to sweep the cursor across the whole notification area, but the hidden icons add a complication; it would have to be popped out and then swept). – Synetech Jun 17 '19 at 09:10
  • There is no need to solve the problem now because I do not use SpeedFan anymore. Thanks to all of you anyway. – Matthew Wai Jun 17 '19 at 15:40

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
  • 21
  • 2
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
  • 430
  • 3
  • 9
  • I found a simple solution: download NoTrayOrphans.exe from http://www.autohotkey.net/~Nazzal/Other/NoTrayOrphans.exe – Matthew Wai Oct 16 '15 at 08:01
  • @matthew-wai - I'm suprised i didn't stumble over that one. Still, using `WinClose("SpeedFan")` instead of `taskkill /F /IM` seems cleaner in this case since SpeedFan wont be killed but properly closed. – Limer Oct 16 '15 at 08:33
  • `WinClose("speedfan.exe")` doesn't work at my end, so I can only use NoTrayOrphans.exe, which I found after searching many relevant webpages. – Matthew Wai Oct 16 '15 at 11:58
  • @matthew-wai: An AutoIt script with **`WinClose("SpeedFan")`** (without `.exe` - it's the name of the window, not the executable) works perfectly for me but it requires admin rights (just as `taskkill`). – Limer Oct 16 '15 at 12:31
  • `WinClose("SpeedFan")` doesn't work either at my end. Nothing happens when it is run. – Matthew Wai Oct 16 '15 at 14:23
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
Elim Garak
  • 101
  • 3
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,875
  • 11
  • 12
  • 19