Restore *all* systray icons after a explorer crash?

Discuss anything related to portable freeware here.
Message
Author
User avatar
david.lynch
Posts: 78
Joined: Tue May 04, 2010 8:04 am

Restore *all* systray icons after a explorer crash?

#1 Post by david.lynch »

Hello everyone! :D

This is a old wish. Every Windows has a explorer.exe, and every explorer.exe can crash... Then, when opened again, most of the systray icons aren't restored.

So, when logoff/logon or a full restart is not an option, what portable app could do the trick of restore all tray icons, no one missing?

Image & Image

User avatar
dany
Posts: 70
Joined: Fri Jun 17, 2011 10:26 pm
Location: netherlands

Re: Restore *all* systray icons after a explorer crash?

#2 Post by dany »

What OS? There are some programs out there but they're pretty much useless for Vista/Win7... Most are even 98/2000/ME only.
Afaik it's not doable... not in a reliable way anyway. Explorer has had the ability to restore icons right from it's first incarnation. However, for this to occur, systray programs have to be set to perform this behaviour; Explorer cannot do it by itself. The majority of systray programs don't behave properly and will, if Explorer crashes or is restarted, fail to redraw themselves.
As a result, all the programs I know of scan your startup folders/registry and then check if any of those programs listed are (still) running. If so, they are killed and restarted (forced). This will restore the systray icon for that program, but you'll also lose any data that's not saved, which is exactly the thing you want to avoid in the first place... right?
Also, it's just a symptom, don't cure the symptom, cure the cause. Explorer can crash, but not without a reason. If it happens very rarely, ok no worries. If it happens often, I'd scan the system for viruses, malware, corrupted files, missing or unregistered dll's, faulty settings etc.
Anyway, an old thread as a starter: http://www.donationcoder.com/forum/inde ... pic=2507.0 although I can not say if any of the software mentioned is actually portable, never tested it myself...
Good luck!

User avatar
david.lynch
Posts: 78
Joined: Tue May 04, 2010 8:04 am

Re: Restore *all* systray icons after a explorer crash?

#3 Post by david.lynch »

hello dany, thanks for the replies, systems are xp and 2003.

it's rare to happen, but sometimes we can not do a full restart so a 'systray rebuilder' is a old wanted Image

User avatar
dany
Posts: 70
Joined: Fri Jun 17, 2011 10:26 pm
Location: netherlands

Re: Restore *all* systray icons after a explorer crash?

#4 Post by dany »

Well, these are really old and I can't really test for portability (win7x64 here), but I wouldn't bet my money on it...

Tray Manager: http://wittswallpapers.com/Oldies/indexoldies.html near the bottom of the page (Windows 95, Windows 98, Windows ME, Windows NT 4, Windows 2000, WinXp)

TraySaver: http://www.mlin.net/other.shtml near the bottom of the page (Win9x, ME, and NT 4.0)

Win-Res-Q: http://magnetiq.com/pages/freeware/#winresq (98, ?)

Correctif Explorer v2.2: http://www.freewareweb.com/cgi-bin/archive.cgi?ID=1461 (doesn't say what OSes)

Correctif forces a shutdown and restart of any systray programs and the others probably do too.
Tray Manager can restore systray icons without logoff/reboot and could be made portable if you shut it down with

Code: Select all

trayman -u
which removes any registry entries. It also comes with source code so... maybe you could hack something together yourself :)

The only alternative I know of is shareware: PS Tray Factory at http://www.pssoftlab.com/pstf_info.phtml and definitely not portable.

User avatar
david.lynch
Posts: 78
Joined: Tue May 04, 2010 8:04 am

Re: Restore *all* systray icons after a explorer crash?

#5 Post by david.lynch »

hello again, dany! Image

The only one from your list that seems to do it is PS Tray Factory:
restore system tray icons after Explorer.exe crash
I've found a topic that states the following:
"Your application will still be running its just that the icon has been lost. All you need to do is re-add the icon via Shell_NOtifyIcon.
Of course the trick is knowing when to do this. One way envolves listening for the registered message "TaskbarCreated".
Search MSDN for RegisterWindowMessage and "TaskbarCreated" for more info."
(from http://www.experts-exchange.com/Program ... 26354.html)

Since it seems to be a pretty simple job, I'll keep looking for an alternative to PS Tray Factory.
Image

User avatar
dany
Posts: 70
Joined: Fri Jun 17, 2011 10:26 pm
Location: netherlands

Re: Restore *all* systray icons after a explorer crash?

#6 Post by dany »

david.lynch wrote:The only one from your list that seems to do it is PS Tray Factory
not quite:
Tray Manager lets you control the explosion of icons in your system tray by creating a submenu for the icons you use less frequently and restores the icons in your system tray after an Explorer crash.
I quickly looked over the source code and as far as I can tell it uses TaskbarCreated & Shell_NotifyIcon to do so. It doesn't seem to force-restart all programs in the systray so that's cool.

It's not as simple as you think with TaskbarCreated & Shell_NotifyIcon. The software that owns the icon in the systray has to listen to the TaskbarCreated event and call Shell_NotifyIcon when necessary. And in this respect the majority of programs don't behave properly, hence the missing icons after a crash.
A program can listen to the TaskbarCreated event, no problems there. Let's call it restore.exe. whatever.exe's icon is missing from the systray. restore.exe can only do it's job if it can create a proper handle to whatever.exe's icon to pass on to Shell_NotifyIcon. Getting that handle is the hard part. The only way I can think of, or atleast the easiest way, would be if restore.exe builds a copy of the icons in systray and use that list to restore the systray after a crash. Ad then you'll have to link those icons to their respective program windows. Afaik that's what Tray Manager does.
Unfortunately the Tray Manager license doesn't allow for modifications and redistribution of the source, so I'm kinda stuck there...

If you do find an alternative, be sure to drop us a line too!

User avatar
david.lynch
Posts: 78
Joined: Tue May 04, 2010 8:04 am

Re: Restore *all* systray icons after a explorer crash?

#7 Post by david.lynch »

well explained, now my I have much less expectations... :(

Image & Image

User avatar
dany
Posts: 70
Joined: Fri Jun 17, 2011 10:26 pm
Location: netherlands

Re: Restore *all* systray icons after a explorer crash?

#8 Post by dany »

Hey, you're welcome :wink:

I must say i have never been bothered much by this because a logoff has always been an option. And often I can bring back hidden windows through sysinternal's Process Explorer and save my data. Minimizing those windows sometimes even restores the systray icon... It's a relatively small nuisance as explorer never crashes that often, at least not on me.
Now that I have looked into it deeper, I must say it's an intriguing challenge to solve... I can C++ but I suck at the windows API, I learned to code on linux :P
If you know how to autoIt, check this interesting thread: http://www.autoitscript.com/forum/topic ... stray-udf/

User avatar
david.lynch
Posts: 78
Joined: Tue May 04, 2010 8:04 am

Re: Restore *all* systray icons after a explorer crash?

#9 Post by david.lynch »

That's a *very* interesting post at autoit forum :)

Even the feature of hide a specific tray icon could be useful, I've already looked for something like this in the past and found just PS Tray Factory :(

Please feel free to post any findings! Image

User avatar
dany
Posts: 70
Joined: Fri Jun 17, 2011 10:26 pm
Location: netherlands

Re: Restore *all* systray icons after a explorer crash?

#10 Post by dany »

Hello again!

Well, findings enough. First I dived into the AutoIt manual, I've wanted to familiarize myself with it's API and this was a good opportunity. I must say I'm thoroughly impressed, although not as powerful as my usual tools of automation (Python, Perl, sh, etc.) in some areas. But it can do some unique things they can't and I'm definitely seeing lots of potential!

Ok, back to the system tray problem. Here are a few findings on that:
- The Notification Area (actual name) is a control of the Desktop process (Explorer). It's not a separate process, nor is it a separate window.
- The icons themselves are also controls of Explorer, not separate processes or windows.
- Processes with an icon in the Notification Area are not necessarily child-processes of Explorer. Nor do they need to have a window.

Now, in AutoIt I can access said Notification Area control and get a correct number count of the icons, both visible and hidden. So far no worries. But thus far I've been unable to retrieve the underlying processes of the icon controls. AutoIt forum searches do seem to hint that it can be done, but so far I've been unable to do so. Maybe it's because I'm on Win 7 64-bit. Either way, I can't get any of those code snippets to work, they all report only one process (AutoIt3.exe) and that's not even in the Notification Area!
Add to that the fact that Win 7 seems to introduce it's own unique set of problems (why am I not surprised...) regardless of it's bitness and my relative unfamiliarity with the WINApi and you can see I'm a bit lost at the moment... Btw, most topics seem to hint that it's relatively easy with DLL injection, but that's just... dirty.
And that's only half of the problem. Even if I can access the underlying processes, how do I reattach them to the Notification Area after a crash without a forced restart? I haven't looked into that yet (tackling one problem at a time) but I'm sure it won't be as easy as Shell_NotifyIcon(icon, process, other, arguments, here)... A forced restart of all processes would be no problem but not what you were looking for.

Can it be done? Yes. I mean if PS Tray Factory can do it, it must be possible, right? Can it be done in AutoIt? Well, probably, but it's way beyond the intended use of AutoIt and I am convinced that doing it in C will be not only much easier, the result will also be faster and more stable, DLL injection or not.

tl;dr
So, no luck so far. But 'Systray Restore' has become something of a pet project of mine and I'll certainly keep my eyes open for any possible solutions. If you don't mind a forced restart it would cut the problem in half :lol:
And atleast I'm learning AutoIt thanks to you :wink:

User avatar
david.lynch
Posts: 78
Joined: Tue May 04, 2010 8:04 am

Re: Restore *all* systray icons after a explorer crash?

#11 Post by david.lynch »

Well, hello dany! Image

Even if we still don't have the solution, I'm quite happy with all that information and progress!

Here, I'm using XP SP3 and Server 2003 SP2, all x32.

Please correct me If I'm wrong, but maybe could be a good idea to 'trace' how PS Tray Factory does his magic. Something like

a debug, breakpoint, etc. (sorry, I'm not a programmer as you can see Image)

Image & Image & let us hear again from you!

User avatar
dany
Posts: 70
Joined: Fri Jun 17, 2011 10:26 pm
Location: netherlands

Re: Restore *all* systray icons after a explorer crash?

#12 Post by dany »

david.lynch wrote:Please correct me If I'm wrong, but maybe could be a good idea to 'trace' how PS Tray Factory does his magic.
Could do, but it's closed source, e.g. off limits... And if by any chance it uses DLL injection rather than system calls we're still going nowhere... But there's some old freeware/open source stuff I can check out, like Tray Manager. Sounds like a plan, thanks for the suggestion!

The 32/64-bit issue is actually a Windows 7 vs Most Other Windows issue I've discovered. The controls have different class-names, I'm just accessing the wrong controls (and the whole new Aero thingy is complicating matters as well). I need to build in some extra checks in my code.
So far 64-bitness has not been a problem really... I'm gonna visit by a friend tomorrow and try my code on his XP.
david.lynch wrote:sorry, I'm not a programmer
:D me neither really, but strong my google-fu is.

User avatar
david.lynch
Posts: 78
Joined: Tue May 04, 2010 8:04 am

Re: Restore *all* systray icons after a explorer crash?

#13 Post by david.lynch »

dany wrote:
david.lynch wrote:sorry, I'm not a programmer
:D me neither really, but strong my google-fu is.
Image

wise words, I'm going to keep that for myself Image

User avatar
guinness
Posts: 4118
Joined: Mon Aug 27, 2007 2:00 am
Contact:

Re: Restore *all* systray icons after a explorer crash?

#14 Post by guinness »

It would be an interesting project to do in AutoIt.

User avatar
joby_toss
Posts: 2970
Joined: Sat Feb 09, 2008 9:57 am
Location: Romania
Contact:

Re: Restore *all* systray icons after a explorer crash?

#15 Post by joby_toss »

Yes, it would, as I recently experienced an explorer.exe crash myself when updating FileMenu Tools (I was unregistering the .dll) and my Comodo Firewall icon stopped displaying the network traffic. :)

Post Reply