Page 1 of 2

Refresh System tray Icons

Posted: 02 Jul 2016, 07:23
by pieter
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

Re: Refresh System tray Icons

Posted: 02 Jul 2016, 11:35
by GEV
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.

Re: Refresh System tray Icons

Posted: 02 Jul 2016, 15:56
by pieter
Not working :( tried with ToolbarWindow321 and ToolbarWindow3211

Re: Refresh System tray Icons

Posted: 02 Jul 2016, 16:04
by GEV
After closing or killing a prozess you should use "Process, WaitClose" or add a sleep to your script before refreshing the notification area.

Re: Refresh System tray Icons

Posted: 03 Jul 2016, 07:40
by pieter
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

Re: Refresh System tray Icons  Topic is solved

Posted: 03 Jul 2016, 07:49
by Noesis
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).

Re: Refresh System tray Icons

Posted: 03 Jul 2016, 08:00
by GEV
Try Noesis's approach. Works for me too (on Win10). Thanks for sharing, Noesis!

Re: Refresh System tray Icons

Posted: 03 Jul 2016, 09:06
by Scoop8
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?

Re: Refresh System tray Icons

Posted: 03 Jul 2016, 12:59
by pieter
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 :/

Re: Refresh System tray Icons

Posted: 03 Jul 2016, 16:25
by punchin
Put Tray_Refresh() somewhere in your code to call the function.

Re: Refresh System tray Icons

Posted: 04 Jul 2016, 01:37
by Noesis
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.

Re: Refresh System tray Icons

Posted: 04 Jul 2016, 04:07
by pieter
Thanks!

Its working with Noesis Script! :D

Re: Refresh System tray Icons

Posted: 04 Jul 2016, 07:26
by Scoop8
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 :)

Re: Refresh System tray Icons

Posted: 07 Jan 2017, 02:27
by BullFrog
Do you mind sharing what program that was?

Re: Refresh System tray Icons

Posted: 07 Jan 2017, 12:02
by BullFrog
Or does it work with W10 for anyone? because the script above in an AHK alone does nothing for me, Ambibox is still there.

Re: Refresh System tray Icons

Posted: 26 Jun 2017, 21:04
by masato
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%
}

Re: Refresh System tray Icons

Posted: 11 Dec 2017, 05:14
by Rayth
@masato : Work great on windows 10, thx !

Re: Refresh System tray Icons

Posted: 13 Mar 2018, 17:07
by neogna2
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"				
				]

Re: Refresh System tray Icons

Posted: 27 Jan 2019, 09:45
by IceLancer
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

Re: Refresh System tray Icons

Posted: 11 Apr 2020, 15:17
by Cr8zy_Ivan
@masato (& @Noesis for initial script), Thank you! The script works perfectly!