• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

detecting shell close & startup


Is there a message notifying you of windows shell (normally explorer.exe) closing and starting ?

I guess you can periodically check if the shell EXE is running, but is there a standard way of notifying applications about shell startup and shutdown ?
1 Solution
For shutdown, the applications will receive the WM_QUERYENDSESSION and WM_ENDSESSION messages. For startup, you may add an applet to the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run registry key. Once the applet starts, it boardcasts a notification message (RegisterWindowMessage).
byangAuthor Commented:
I wasn't talking about windows shutdown, which causes WM_QUERYENDSESSION, but shutting down shell without closing windows. For shell startup, I guess the applet would work, since the shell is supposed to process the RUN registry key.
Shell is the ordinary Windows app, so you can use, say, WH_SHELL hook.

Check if the created/destroyed window has, for example, "Shell_TrayWnd" class name.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

byangAuthor Commented:
Hmm, is shell required to create a Shell_TrayWnd window, or any window at all ? And can other applications create Shell_TrayWnd too ?

But I'm willing to assume the shell will create at least one top level window upon startup, this is Windows after all.

The hook approach might be workable, I just check the window's HINSTANCE name and compare it to the shell EXE name.

Still, I don't like it as it is so hackish. I really like to find a better way.
Shell_TrayWnd is the top-level window which is created by explorer.exe in 95/98/NT4/2000. It's unlikely that other app will use this class name.

<<I just check the window's HINSTANCE name and compare it to the shell EXE name. >>
It's also possible.

It's fully documented way (at least, with exe name by HINSTANCE).
No hacks at all.

You can reject my answer and continue to search for a better way, of course.
AFAIK, Nick's suggestion is the cleanest possible way.

One hint to byang: You can't transport the HInstance value from the hook dll to your main app, and then get the executable name in the main app, because the HInstance value is only valid in the process which owns the window. So you have to ask the executable name in the hook dll function. Well, probably you knew that already...   :-)

Regards, Madshi.
byangAuthor Commented:
Madshi, yes I'm sending a lot of info from my hook DLL to my EXE by sending WM_COPYDATA.

OK I'll accept it NickRepin's answer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now