Refresh System tray Icons Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
pieter
Posts: 33
Joined: 29 Jun 2016, 06:16

Refresh System tray Icons

02 Jul 2016, 07:23

Hello!

I'm trying to get rid of those icons on the notification area that still showing if you kill a proccess, tried several scripts i've found on the old forums but none worked for me.. :(

I have windows 10 x64

Any solution?
Thanks
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Refresh System tray Icons

02 Jul 2016, 11:35

Try

Code: Select all

WM_MOUSEMOVE := 0x200
ControlGetPos, xTray,, wTray,, ToolbarWindow321, ahk_class Shell_TrayWnd
endX := xTray + wTray
x := 5
y := 12
Loop
{
	if (x > endX)
		break
	point1 := (y << 16) + x	
	point2 := (x << 16) + y		      ; If the notification area has two rows
	point3 := (x << 16) + 5*y/2	      ; If the notification area has three rows
	PostMessage, %WM_MOUSEMOVE%, 0, %point1%, ToolbarWindow321, ahk_class Shell_TrayWnd
	PostMessage, %WM_MOUSEMOVE%, 0, %point2%, ToolbarWindow321, ahk_class Shell_TrayWnd
	PostMessage, %WM_MOUSEMOVE%, 0, %point3%, ToolbarWindow321, ahk_class Shell_TrayWnd
		x += 18
}
Replace "ToolbarWindow321" with "ToolbarWindow3211" if you have Windows 10.
pieter
Posts: 33
Joined: 29 Jun 2016, 06:16

Re: Refresh System tray Icons

02 Jul 2016, 15:56

Not working :( tried with ToolbarWindow321 and ToolbarWindow3211
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Refresh System tray Icons

02 Jul 2016, 16:04

After closing or killing a prozess you should use "Process, WaitClose" or add a sleep to your script before refreshing the notification area.
pieter
Posts: 33
Joined: 29 Jun 2016, 06:16

Re: Refresh System tray Icons

03 Jul 2016, 07:40

GEV wrote:After closing or killing a prozess you should use "Process, WaitClose" or add a sleep to your script before refreshing the notification area.

Not working neither :(

Using

Code: Select all

Process, Close, LErt.exe

Sleep 10000

WM_MOUSEMOVE := 0x200
ControlGetPos, xTray,, wTray,, ToolbarWindow321, ahk_class Shell_TrayWnd
endX := xTray + wTray
x := 5
y := 12
Loop
{
	if (x > endX)
		break
	point1 := (y << 16) + x	
	point2 := (x << 16) + y		      ; If the notification area has two rows
	point3 := (x << 16) + 5*y/2	      ; If the notification area has three rows
	PostMessage, %WM_MOUSEMOVE%, 0, %point1%, ToolbarWindow321, ahk_class Shell_TrayWnd
	PostMessage, %WM_MOUSEMOVE%, 0, %point2%, ToolbarWindow321, ahk_class Shell_TrayWnd
	PostMessage, %WM_MOUSEMOVE%, 0, %point3%, ToolbarWindow321, ahk_class Shell_TrayWnd
		x += 18
}
 
Using the Window Spy Tool on my windows, the ClassNN it's still ToolbarWindow321, not 3211. Also Shell_TrayWnd is the class for the taskbar, the traybar says its class NotifyIconOverflowWindow
Noesis
Posts: 301
Joined: 26 Apr 2014, 07:57

Re: Refresh System tray Icons  Topic is solved

03 Jul 2016, 07:49

I use the following function, which works for me on win 10:

Code: Select all

Tray_Refresh()
{
	WM_MOUSEMOVE := 0x200
	HiddenWindows := A_DetectHiddenWindows
	DetectHiddenWindows, On
	TrayTitle := "AHK_class Shell_TrayWnd"
	ControlNN := "ToolbarWindow322"
	IcSz := 24
	Loop, 2
	{
		ControlGetPos, xTray,yTray,wdTray,htTray, %ControlNN%, %TrayTitle%
		y := htTray - 10
		While (y > 0)
		{
			x := wdTray - IcSz/2
			While (x > 0)
			{
				point := (y << 16) + x
				PostMessage, %WM_MOUSEMOVE%, 0, %point%, %ControlNN%, %TrayTitle%
				x -= IcSz/2
			}
			y -= IcSz/2
		}
		TrayTitle := "AHK_class NotifyIconOverflowWindow"
		ControlNN := "ToolbarWindow321"
		IcSz := 32
	}
	DetectHiddenWindows, %HiddenWindows%
	Return
}
GEV's should work too but I suspect he's on win 7 and hence gave the wrong control class (should be ToolbarWindow322).
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Refresh System tray Icons

03 Jul 2016, 08:00

Try Noesis's approach. Works for me too (on Win10). Thanks for sharing, Noesis!
Scoop8
Posts: 2
Joined: 03 Jul 2016, 08:16

Re: Refresh System tray Icons

03 Jul 2016, 09:06

I tried Noesis' script but can't get it to work for me.

I'm on Win 7x64 Home Premium OEM. I'm using the ToolbarWindow322 value. I tried it with 321.

When I run Noesis's script, it's not giving an error; appears to run ok but a deleted AHK process icon remains in my Tray (unless I clear it manually with the mouse).

My issue may be that I'm still running an old AHK version, Version v1.0.95.00 . I haven't upgraded since all of my scripts are running great; never an issue so that's made me hesitant to upgrade AHK.

Could that be the reason that Noesis's script doesn't work for me?
pieter
Posts: 33
Joined: 29 Jun 2016, 06:16

Re: Refresh System tray Icons

03 Jul 2016, 12:59

Noesis wrote:I use the following function, which works for me on win 10:

Code: Select all

Tray_Refresh()
{
	WM_MOUSEMOVE := 0x200
	HiddenWindows := A_DetectHiddenWindows
	DetectHiddenWindows, On
	TrayTitle := "AHK_class Shell_TrayWnd"
	ControlNN := "ToolbarWindow322"
	IcSz := 24
	Loop, 2
	{
		ControlGetPos, xTray,yTray,wdTray,htTray, %ControlNN%, %TrayTitle%
		y := htTray - 10
		While (y > 0)
		{
			x := wdTray - IcSz/2
			While (x > 0)
			{
				point := (y << 16) + x
				PostMessage, %WM_MOUSEMOVE%, 0, %point%, %ControlNN%, %TrayTitle%
				x -= IcSz/2
			}
			y -= IcSz/2
		}
		TrayTitle := "AHK_class NotifyIconOverflowWindow"
		ControlNN := "ToolbarWindow321"
		IcSz := 32
	}
	DetectHiddenWindows, %HiddenWindows%
	Return
}
GEV's should work too but I suspect he's on win 7 and hence gave the wrong control class (should be ToolbarWindow322).
Its working :D But only If assign it a Hotkey, how I can make it work without the hotkey?

Because if I just paste that code into an .ahk and run it, does nothing :/
punchin
Posts: 439
Joined: 17 Jan 2014, 17:54

Re: Refresh System tray Icons

03 Jul 2016, 16:25

Put Tray_Refresh() somewhere in your code to call the function.
Noesis
Posts: 301
Joined: 26 Apr 2014, 07:57

Re: Refresh System tray Icons

04 Jul 2016, 01:37

Scoop8 I used to use this exact script in Win7 (home premium x64 OEM as well) and it should work provided you use ToolbarWindow321 for the controlNN.

It's possible it's the AHK version, personally I've never had an issue upgrading ahk to latest versions with regard to script backwards compatibility and would recommend you upgrade to latest version of AHK regardless of this being the cause of this issue.

Also It's possible the ahk icon not being cleared is from the instance running this function (i.e. it's active until the function finishes), in which case call it from a script which uses #Notrayicon. Personally I don't do this as my ahk icons all self clear upon script completion anyway, but something to try perhaps.
pieter
Posts: 33
Joined: 29 Jun 2016, 06:16

Re: Refresh System tray Icons

04 Jul 2016, 04:07

Thanks!

Its working with Noesis Script! :D
Scoop8
Posts: 2
Joined: 03 Jul 2016, 08:16

Re: Refresh System tray Icons

04 Jul 2016, 07:26

Noesis wrote:Scoop8 I used to use this exact script in Win7 (home premium x64 OEM as well) and it should work provided you use ToolbarWindow321 for the controlNN.

It's possible it's the AHK version, personally I've never had an issue upgrading ahk to latest versions with regard to script backwards compatibility and would recommend you upgrade to latest version of AHK regardless of this being the cause of this issue.

Also It's possible the ahk icon not being cleared is from the instance running this function (i.e. it's active until the function finishes), in which case call it from a script which uses #Notrayicon. Personally I don't do this as my ahk icons all self clear upon script completion anyway, but something to try perhaps.
Thanks for the info. I need to upgrade to the latest version, just haven't done it yet. I'll get that done this weekend.

I tried the script using -> ControlNN := "ToolbarWindow321" but it didn't work for me. I tested the script this way:

- Run one of my ahk scripts, a "reminder" script that I use all the time when I'm on my PC.
- Deleted the ahk script using "Process Explorer".
- Checked Sys Tray; verified the deleted process orphaned Icon was present as expected.
- Ran the above script in this thread, using the "321" value in both lines of the script for the 'controlNN' variable.

I didn't work for me as the orphaned Icon remained in the Tray after running the script.

I found a standalone exe file online that refreshes the Tray and removes orphaned Icons so my issue is fixed using another method.

I want to get the ahk script to work as I like to learn from this forum and use ahk for such tasks but I'm a novice compared to just about everyone else here :) so it takes me a while to grasp some things here. (if you all saw my 'Reminder.ahk' script, you'd :lol: at it :) , but it works for me.)

Thanks for the reply :)
BullFrog
Posts: 10
Joined: 13 Mar 2016, 04:35

Re: Refresh System tray Icons

07 Jan 2017, 02:27

Do you mind sharing what program that was?
BullFrog
Posts: 10
Joined: 13 Mar 2016, 04:35

Re: Refresh System tray Icons

07 Jan 2017, 12:02

Or does it work with W10 for anyone? because the script above in an AHK alone does nothing for me, Ambibox is still there.
User avatar
masato
Posts: 21
Joined: 08 Sep 2015, 13:38

Re: Refresh System tray Icons

26 Jun 2017, 21:04

Soo, having upgraded to W10 recently, I noticed this doesn't work anymore.
Here's the version I came-up with:

Code: Select all

Tray_Refresh()

Tray_Refresh() {
/*		Remove any dead icon from the tray menu
 *		Should work both for W7 & W10
 */
	WM_MOUSEMOVE := 0x200
	detectHiddenWin := A_DetectHiddenWindows
	DetectHiddenWindows, On

	allTitles := ["ahk_class Shell_TrayWnd"
			, "ahk_class NotifyIconOverflowWindow"]
	allControls := ["ToolbarWindow321"
				,"ToolbarWindow322"
				,"ToolbarWindow323"
				,"ToolbarWindow324"]
	allIconSizes := [24,32]

	for id, title in allTitles {
		for id, controlName in allControls
		{
			for id, iconSize in allIconSizes
			{
				ControlGetPos, xTray,yTray,wdTray,htTray,% controlName,% title
				y := htTray - 10
				While (y > 0)
				{
					x := wdTray - iconSize/2
					While (x > 0)
					{
						point := (y << 16) + x
						PostMessage,% WM_MOUSEMOVE, 0,% point,% controlName,% title
						x -= iconSize/2
					}
					y -= iconSize/2
				}
			}
		}
	}

	DetectHiddenWindows, %detectHiddenWin%
}
And in case someone'd like to test it out:

Code: Select all

#SingleInstance, Off
#Persistent

Loop, %0% { ; Command-Line Parameters
	param := %A_Index%
	if (param="/Secondary")
		isSecondary := true
}

if !(isSecondary) {
	AHK_PIDS := {}
	Progress, , ,Running multiple process of the script,Tray_Refresh
	Loop 5 { ; Running instances
		Progress,% (100/5) * A_Index
		
		Run,% A_ScriptFullPath " /Secondary", , ,scriptPID
		AHK_PIDS.Push(scriptPID)
		Sleep 10
	}
	Progress, Off
	for id, pid in AHK_PIDS { ; Closing instances
		Process, Close,% pid
	}
	Sleep 100
	MsgBox, 4096,Tray_Refresh,% "Close this box to remove all dead icons from the tray."
	Tray_Refresh()
	ExitApp
}
Return

Tray_Refresh() {
/*		Remove any dead icon from the tray menu
 *		Should work both for W7 & W10
 */
	WM_MOUSEMOVE := 0x200
	detectHiddenWin := A_DetectHiddenWindows
	DetectHiddenWindows, On

	allTitles := ["ahk_class Shell_TrayWnd"
			, "ahk_class NotifyIconOverflowWindow"]
	allControls := ["ToolbarWindow321"
				,"ToolbarWindow322"
				,"ToolbarWindow323"
				,"ToolbarWindow324"]
	allIconSizes := [24,32]

	for id, title in allTitles {
		for id, controlName in allControls
		{
			for id, iconSize in allIconSizes
			{
				ControlGetPos, xTray,yTray,wdTray,htTray,% controlName,% title
				y := htTray - 10
				While (y > 0)
				{
					x := wdTray - iconSize/2
					While (x > 0)
					{
						point := (y << 16) + x
						PostMessage,% WM_MOUSEMOVE, 0,% point,% controlName,% title
						x -= iconSize/2
					}
					y -= iconSize/2
				}
			}
		}
	}

	DetectHiddenWindows, %detectHiddenWin%
}
Rayth
Posts: 11
Joined: 11 Mar 2017, 10:56

Re: Refresh System tray Icons

11 Dec 2017, 05:14

@masato : Work great on windows 10, thx !
neogna2
Posts: 586
Joined: 15 Sep 2016, 15:44

Re: Refresh System tray Icons

13 Mar 2018, 17:07

masato wrote:Soo, having upgraded to W10 recently, I noticed this doesn't work anymore.
Here's the version I came-up with
Thank you for the script. It worked for me in Win10 after I modified this line

Code: Select all

	allControls := ["ToolbarWindow321"
				,"ToolbarWindow322"
				,"ToolbarWindow323"
				,"ToolbarWindow324"]
into

Code: Select all

	allControls := ["ToolbarWindow321"
				,"ToolbarWindow322"
				,"ToolbarWindow323"
				,"ToolbarWindow324"
				,"ToolbarWindow325"
				,"ToolbarWindow326"				
				]
IceLancer
Posts: 1
Joined: 30 Dec 2018, 12:48

Re: Refresh System tray Icons

27 Jan 2019, 09:45

Selukwe wrote:
23 Apr 2017, 03:53
Try this freeware: SystemTrayRefresh. Will do the job without any programming. Find at http://visualfantasy.tk
Doesn't do anything to tray , at least regarding remaining AHK script icon. (win10)

As for script solution above, it works. But system specific, which doesn't work for me. :( Need it to be system free, aka to work on any windows 7-10
User avatar
Cr8zy_Ivan
Posts: 131
Joined: 30 Mar 2019, 18:20

Re: Refresh System tray Icons

11 Apr 2020, 15:17

@masato (& @Noesis for initial script), Thank you! The script works perfectly!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 120 guests