Link to home
Start Free TrialLog in
Avatar of Madshi
Madshi

asked on

stop explorer cleanly

How can I stop the explorer (= startmenu + desktop) cleanly without any user interaction?
In the moment I'm using TerminateProcess, but after some stops&starts the win9x PCs get instable.
But I can logoff and logon again 1000 times without any problems. So there must be a way to stop the explorer cleanly.
But: I don't want to logoff! I just want to stop the explorer!
(It's for a remote control software, that fully controls a client PC).

I need it for all win9x versions, NT4 and win2000.

Thank you...   :-)
Avatar of Madshi
Madshi

ASKER

P.S: If you need more points, just say so...
Avatar of Zoppo
Hi Madshi,

Only thing I found about it is an article in MSDN ID: Q216638 'HOWTO: Programmatically Force Windows 95 and Windows 98 to Log Off' ... did you see this before?
This article even describes how to stop explorer process using TerminateProcess.

ZOPPO
But, unfortunately, the used ToolHelp-function won't work with NT4 or earlier...
Avatar of Madshi

ASKER

Hi Zoppo, thanx for your input. But as I said, I'm already using TerminateProcess to stop the explorer, and after doing that several times, win9x PCs get instable somehow...   :-(
listening ....
Ok, I have some ideas but it's not exactly what you want. If you go in to "Shut Down" dialog and pres Ctrl+Alt+Shift and click on Cancel button the explorer will go out. So, probably you can use something like Spy or whatever and check what is happening, probably there is some spesial message. As I know such way exist only on win9x (with dialog and such key combination).
Avatar of Madshi

ASKER

Hey, nice trick!  :-)  I didn't know that before.

Hmmm... Would you test that for me? That would be great! (I don't have Spy on my harddisk.)

Well, even if it only works for win9x, that would help me a lot already. So I would be willing to give you those points, if you find a special message that works under all win9x versions.

Thank you...

Regards, Madshi.
Ok, I gonna try
Here it is:

HWND hwnd = ::FindWindow("Shell_TrayWnd", NULL);

if(hwnd)
    ::PostMessage(hwnd, WM_QUIT, 0, 0);
It also works under w2k :)
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i ONLY think that ...

HWND hwndShell = FindWindow("Shell_TrayWnd", NULL);
PostMessage(hwndShell, WM_QUIT, 0, 0L);
WinExec("Explorer.exe",SW_SHOW);



will do the Job !!
Listening....
The truth is that Explorer sends two messages as a response on Shift-Control-Alt+Cancel:

PostMessage("Progman",WM_QUIT,0,1)
PostMessage("Shell_TrayWnd",WM_QUIT,0,0)

on my NT, at least.

Probably, Progman sends the WM_QUIT message to Shell_TrayWnd when it quits.
No, right after the DialogBoxParam() there are two adjacent PostMessage calls.
Seems that it doesn't matter anyway and WM_QUIT may be sent to the one of them.
Of course, it's better to follow the MS knowledge base article.
Avatar of Madshi

ASKER

Thank you, guys. I'm using PostMessage(Progman, WM_QUIT, 0, 0) now and it works quite nice under win95, win98, win2000. Didn't test NT4, but I'm quite sure that it will work there, too.
Now it's a bit difficult for me to decide who should get the points.
I would like to split them between MichaelS and chensu, because Michael was the first one, and chensu gave me that "official" article (chensu, it seems to me you have an article for EVERY problem... :-).
Would that be alright for all of you?

Nick, I tried PostMessage(Progman, WM_QUIT, 0, 1), too. Strange thing! It opens the shutdown dialog!!!  #8-O

Regards, Madshi.
>>I tried PostMessage(Progman, WM_QUIT, 0, 1), too. Strange thing! It opens the shutdown dialog!!!

Really? Have you tried both PostMessages, one right after another?
Anyway, it doesn't matter, my comment doesn't pretend on answer.
listening...
Community Support has reduced points from 333 to 200
Hello everyone,

Reducing points to 200 to allow for split.

Madshi, you can now accept one of the comments in this thread as an answer. To award the other Expert, you can create a new question in this topic area with a title of 'For ExpertName -- 10507038' using that Experts username.

Remember, the Accept Comment as Answer button is in the header of the comment.

For your convenience, you can use this link to create the new question (right click and open in a new window):
https://www.experts-exchange.com/bin/NewQForm?ta=45

darinw
Customer Service
Avatar of Madshi

ASKER

Comment accepted as answer
Avatar of Madshi

ASKER

Thank you all for your help!