|
Beste,
Ik zie dat je ook van België bent
Ik heb een programma dat om de 4 uur gekilled wordt in Windows 7. Per dag komen er in de tray dus 6 icoontjes bij ... Als ik er mey de muis over ga, dan gaan ze allemaal behalve het ene dat het draaiende programma voorstelt weg. Dus heel vervelend al sik het programma wil oproepen moet ik eerst die nest "dode" icoontjes wegwerken.
Ik dacht dat uw programma een oplossing zou bieden, doch bij mij werkt het niet...
Als ik de exe opstart zie ik jouw programma als extra icoontje. Ondanks dat het om de 5 seconden iets moet doen, blijven alle dode icoontjes staan. Als ik "Run now" kies, ook dan blijven ze gewoon staan ...
Ik zou het op prijs stellen als u me eens zou kunnen contacteren hieromtrent. Ook zou een console versie (een command line versie zonder output en die na "opkuis" elke keer stopt) handig zijn zodat je die via Windows Taskplannner om de XX minuten/uur kan zelf oproepen handig zijn. Via een .vbs script kan je zelfs maken dat je niks in windows ziet. Voordeel is ook dat er niet een zoveelste programma continu opgestart is en er in taakbeheer geen extra lijntje is. Na uitvoeren verdwijnt immers iedere keer het programma.
U kan me contacteren op clement.germain@hotmail.be
|
|
|
|
|
Hi,
Using this tool under Windows7 or 8 has been discussed before in this thread. In summary, the tool needs minor tweeks, and then seems to work perfectly when Windows is set up to "always show all icons and notifications on the taskbar" (a checkbox accessible through control panel "Taskbar and Navigation" under Win8, and something similar under Win7). And mmbrian indicated a way to modify my code and make it work also when the checkbox isn't checked (I haven't tested that).
Teaching my tool not to show a NotifyIcon, or changing it into a console app, shouldn't be hard (but see note below); and that is why the articles on CodeProject offer the source code in the first place: showing you how things can be done, and enabling you to adapt them to your needs.
PS: killing a process isn't nice; if the process code is available and can be modified, it would be better to send it a message to perform an orderly exit, which would allow the process to remove its NotifyIcons itself.
note added 20-dec-2014: the tool's safety system relies on it having and showing a NotifyIcon; if you want to make one without its own NotifyIcon, then the safety pass has to be removed or otherwise disabled too.
modified 21-Dec-14 21:11pm.
|
|
|
|
|
Very helpful piece of code, I was looking for this for half a day - so thanks Luc for sharing it! Juergen
|
|
|
|
|
Hello Luc Pattyn,
First of all thank you very much for this wonderful program, it works fine.
I put the trayiconbuster.exe file it in the autostart folder so that it starts with windows,
though after about 1 hour a window called "Form1" with the button "Remove Obolete Tray Icons"
appears. When i click on the button the program closes entirely, just like when i close the program manually,
this really gets pretty annoying because that window appears than every half an our.
All I want is that window never to appear.
I would be thankful for help.
Nat
|
|
|
|
|
Hi,
the app has a single main form (the one you are complaining about), which normally is Minimized and not shown in the task bar, hence invisible. Initially, i.e. during development, it was permanently visible (WindowState.Normal) and the button was used to test the code. With the form minimized, the app works as intended. AFAICT there is no code that changes the form's visibility, windowstate, or locaion.
There also is nothing with a period of one hour or half an hour. So if the form pops up after such time, my best guess is you have something else that modifies my app's WindowState.
Possible work-around: you could modify the form's Location to some negative numbers (say -10000,-10000) to make it off-screen.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi,
now I changed the Location values of Form1 both to -10000, like you said, it went off-screen.
I also removed the tray icon in the Form1.Designer.cs by setting "this.notifyIcon1.Visible = false;"
But when you press Alt + Tab in Windows, the App is still in the 'Task Switcher' listed with the other tasks.
How can I make it also disappear from the Task Switcher? (I'm using Win 7 64-Bit)
Thank you,
Nat
|
|
|
|
|
I haven't tested this, however Google tells me it suffices to set the form's FormBorderStyle property to FixedToolWindow.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
wow this works flawless Thanks
|
|
|
|
|
It solved a problem that I had with a third party application leaving icons in the tray - saved me tons of work. Many thanks
|
|
|
|
|
I was told Windows 7 has new features, one of them being identical try icons somehow get collected, merged, I don't know the details, except that the "group icons in tray" feature can be disabled. When it is not disabled and icons do get grouped, my app is no longer capable of removing them.
As I don't have Windows 7 around at this time, I can't do anything about it yet. I will look into the matter at some later point in time (probably medio 2010).
Please feel free to provide me with more information if and when available.
Cheers.
modified on Friday, August 28, 2009 6:10 AM
|
|
|
|
|
Hi Luc
Thanks for your great tool!
Together with my friend, we somehow managed to fix this issue with win7.
the point is, when icons are hidden, they no longer exist in any child of Shell_TrayWnd. however, you can find them in NotifyIconOverflowWindow. so you just need to run RemovePhantomIcons another time, this time looking for ToolBarButtons in NotifyIconOverflowWindow like this:
FindNestedWindow(ref hWnd, "NotifyIconOverflowWindow")
FindNestedWindow(ref hWnd, "ToolbarWindow32");
Hope this helps
|
|
|
|
|
Thanks for the feedback and your find.
I never used Windows7 much, but currently a descendant of the above program is running periodically on my Win8 machine; I never had any problems with it, but I now realize that this is due to my choice to "always show all icons".
FYI: I have two issues with missing or disappearing NotifyIcons though (i.e. too few, not too many of them).
1. One seems a general bug in Windows Explorer, at least in Win8. Some of my programs suddenly fail to show their NotifyIcon. Restarting Explorer (or Windows) often fixes this. If not, a registry manipulation is required.
2. the Task Manager's NotifyIcon disappears randomly; I tend to open Task Manager at logon, and keep it minimized, so the NotifyIcon shows the CPU load and provides fast access; but every so often that NotifyIcon goes astray.
|
|
|
|
|
I see. well, we don't have windows 8 right now but surely we'll look into these problems as soon as we get one
|
|
|
|
|
hi,
i just noticed that each time a stale icon is removed, an empty space (probably equal to size of an icon) is left near the clock, so everytime i delete an icon, some free space is left and the traysize isn't reduced. I didn't notice this previously, just noticed it and wanted to ask if you have worked on this issue too. The space is removed when you make a change to system tray (eg change the size or add another icon etc)...
Thankyou
|
|
|
|
|
I've never seen such thing. What operating system and version/service pack are you using?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I have the same problem. Windows Vista SP2
-----
Samara, Russia
|
|
|
|
|
I've never seen that, and as long as it doesn't happen on my Vista machine I'm afraid there isn't much I can do. What program(s) is(are) putting up those NotifyIcons that don't get removed properly?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Happens for me too. So far I've checked in Windows 10 Professional (32-Bit and 64-Bit), and Windows 7 Professional (64-Bit). Run a program that creates a system tray icon, and kill the program with Task Manager. The space is left.
|
|
|
|
|
Thanks for the info.
Since then, I moved on to Windows 10 and incorporated my code in a bigger background task; I'm still not getting the effect you both described. But that may not be a big surprise as there are many taskbar settings, so the circumstances may be different.
If and when I get troubled by the phenomenon, I will try and fix it. Understandably for the moment I will leave things as they are.
Cheers.
|
|
|
|
|
Luc, what are you doing up at this hour? Or are you in Europe? I am actually working all night here in Montana USA.
I fixed the problem, and it is quite simple. I don't know if you wish to do this or not, being that you can't reproduce the issue.
In any event, all you have to do is, if the count of removed icons is greater than zero, add a dummy system tray icon, and then immediately remove it. Use no HWND, no message ID, and no icon. This seems to update the system tray and resize it. To prevent flicker, only do this if an icon has been removed.
As I stated, you certainly don't have to do this if you don't want to, but it seems to work for me.
Also, I made a native, unmanaged, C++ version of your basic code. No UI, it is just a console app which calls the RemovePhantomIcons function once and then exits.
Thanks.
|
|
|
|
|
Hi Mark,
I was up early, and yes I live in Europe.
Your trick with a dummy icon seems plausible, I'll keep it in mind.
Thanks.
|
|
|
|
|
Great Application.
I need to delete an icon from the system tray. I found this application very interesting but to be honest, i am unable to understand even a line in code. You should have provided more explanation of the article. I am unable to understand how an icon with out an image name is deleted. The code and application is no doubt develped by one of the best out there but can u please provide some help in understanding it. I need to delete a process icon . Befor killing the process , can i get a ptr to it and then delete its icon.
Thanks
|
|
|
|
|
Hi,
the goal of the tool was to delete stale icons, i.e. icons for which no process existed any more.
It was and is intended as a tool, to be used; not as a programming example, so I left out a lot of explanation on how to get to the right window, etc etc.
the main sequence of events (in TrayIconBuster.cs) is like this:
1. locate the toolbar that holds all the notify icons, that is what the series of FindNestedWindow calls is about;
2. enumerate all buttons in the toolbar in order to find at least one icon with a live process (could be the tool itself); this is a safety precaution, in case another Windows version does things differently, I don't want to go and change things in an environment I don't recognize; so pass 1 is looking for icons with a process name ending on ".exe".
3. assuming pass 1 succeeds, I enter pass 2 enumerating all buttons again; the ones without process name are the stale ones, and now get sent a TB_DELETEBUTTON message.
So the active code is in here:
if(pass==2 && filename==null) {
SOK=(uint)SendMessage(hWnd, TB_DELETEBUTTON,
new IntPtr(item2), IntPtr.Zero);
if(SOK!=1) throw new ApplicationException("TB_DELETEBUTTON failed");
removedCount++;
}
If you were to change anything, it should be there.
However you say you want to delete a notify icon for a running process; I am not sure that is wise; the process itself will not know. The icon will disappear, and so will the ability to invoke the context menu if any. Anyway, if the app exits, it removes its icons; and if the app gets killed somehow, my tool would remove the icon without requiring any change. So I am not convinced you need to change anything.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi, Thanks for replying
You said "I don't want to go and change things in an environment I don't recognize". This is exactly my problem. I have a 3rd party application installed that has leaks in disconnect. That is when i connect to this program and then disconnect, it doesnot free all of its resources. After some days the 3rd party application crashes,One work around is to stop(kill) the process(3rd party) after it has made all backups and restart it. (if you hav better idea than this, please share... ).
Now, when i kill the process (in my C# application), its icon still remains, which is kind of bothering me. I want to remove the icon too, but again i don't want to look for other stale processes. All i want to do is, take a handle to the process that i am gonna kill, then kill the process and somehow use the handle to remove the icon.
Hope you will provide further help.
Thankyou
|
|
|
|
|
Yes, that is what I was expecting.
My recommendation would be to:
1. kill the app you want to get rid of (manually, by batch file, by an app, whatever);
2. keep my TrayIconBuster running all the time, it will periodically (every 5 seconds) clean up the stale icons; having them around a few seconds won't hurt anyone, and my app is small, so that shouldn't disturb anything. Having it clean up other stale icons than the ones that interest you, is no bother either, they are stale, there is no process attached to them, so all they do is take screen real estate and some memory.
So there is no need to change anything nor create a (modified) app.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|