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 ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.