Link to home
Start Free TrialLog in
Avatar of chulland
chulland

asked on

Restarting Explorer.exe without taskbar items un-minimising.

Hi all,  

I want to restart explorer programaticly... fine, the code below works fine.

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

BUT when the icons reappear on the desktop any loaded programs in the task bar (bottom right minimised to an icon) load in turn as their original un-minimised window.

Is there a cleaner way to restart explorer to make it look seemless?

Thanks in advance
(using windows 2000 pro)
Avatar of grg99
grg99

Suspect you mean "Seamless".    

Maybe try using system() instead of WinExec()?



Avatar of chulland

ASKER

Yes I mean Seamless... spelling not one of my good points.

Can you please expain your comment?  I could use ShellExecute() on Explorer to do the same job.  Would still load up the icons as if you double clicked them.
You could try to refresh the desktop rather than restart it:

    HWND hwndShell = ::FindWindow("Progman", NULL);  
    ::ShowWindow(hwndShell, SW_HIDE);
    ::ShowWindow(hwndShell, SW_SHOWNOACTIVATE);

Regards, Alex

Instead of searching "Progman" you might use HWND_DESKTOP (or NULL) to automatically getting the handle of the current desktop.

I've used system() dozens of times and it has never had any effect on the desktop.  

Oh, sorry, I misunderstood your question!   I thought you wanted to restart YOUR program.

Perhaps we should ask:  WHY do you want to restart Explorer?     Restarting the main user interface to the OS is a rather drastic thing to do.

I require to restart explorer because I have made changes to the shell.  So refreshing the desktop is no good, I need a reload.

Many programs when installing new software require a shell reload whether its to load a dll into the explorer or whatever.

My question remains the same.  The initial code works but the loaded software minimized (bottom right icons), open up when desktop reloads.

Thanks
Are you going to be changing the shell that often that this matters?     :)

>>>> Many programs when installing new software require a shell reload

No, I never heard of of such a thing beside of a reboot. "shell reload" is a UNIX kind of expression and is no common Windows practice.

Dlls, services and drivers are not loaded by Explorer but by Windows. Restarting the explorer will refresh icons, explorer contents menu, some other explorer settings like "Send To..." ... and nothing else. All this will happen automatically as well within some seconds delay, e. g. if you are adding icon links to "All Users\start menu\program files\".

So, I would be interested in your "changes to the shell" that need a restart of the explorer.

Regards, Alex

LOL what is the problem here guys.... I am asking a simple question that require a simple answer (I hope)

WHY I am wanting the restart is not an issue. Even Microsoft offer the solution:-
http://support.microsoft.com/support/kb/articles/Q137/5/72.ASP

BUT it does have this wierd side effect of unminimizing the loaded programs, or reloading them at normal window size.  

Other people do it perfectly, my code doesn't.

The question is why? What am I doing wrong.

Thanks



As for what explorer does, well itsmeandnobodyelse perhaps you have never written shell extensions before?  Explorer does a hell of a lot more than you think by your last comment.  It basically does ANYTHING that I want it to with a "plugin".  ANY DLL can be loaded in there at startup.

Many companies add pugins to exporer and have to restart hence my question.
Here's a hint from the great unwashed out there:

 You can control whether Explorer will restore windows which were open when NT was shutdown. This automatic restoring of windows drives me nuts. It was a problem in OS/2, Windows NT, and now Windows 2000. You don't like it, fix it with the following Windows NT / Windows 2000 registry hack :

Hive: HKEY_CURRENT_USER
Key: Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Name: NoSaveSettings
Type: REG_BINARY
Value: 1
This entry will prevent you from permanently repositioning desktop shortcuts and from adjusting the size and/or position of the Taskbar.

mmmm not sure if this is what I mean, I have seen something on this before.  My icons remain in the same place, the reload of explorer is perfect but any programs that were loaded and minimized come out of their minimized state.

I'll have a look at this and see if it helps any.

Thanks
>>>> well itsmeandnobodyelse perhaps you have never written shell extensions before?

Yes, you are right. But I know a lot of Windows services, dll unload and load, and if you would tell what kind of refreshes you need, I most likely could help you.

One last suggestion before unsubscribing:

Before closing the explorer get the list of all toplevel applications in the taskbar by means of a call to EnumWindows. Find out which windows are minimized by ::IsIconic(hwnd) and save the the window title to be able to identify them later (I don't know whether the hwnd handle changes after restart of Explorer). After restarting the Explorer you could watch by means of EnumWindows which windows have been restored. Send  a WM_SYSCOMMAND + SC_MINIMIZE (WPARAM) message to them and they will minimize (again). Stop the watching if all minimized windows have been invoked.

Regards, Alex
Hi,

I was given the answer through Email from a guy whose product did exactly what I wanted to do after I contacted him.

Here's what he did:-

Kill the process 'explorer.exe' with OpenProcess and TerminateProcess API calls.
In order to find the right ProcessID, enumerate all processes in the system, until finding the 'explorer.exe'. On Windows 9x, use Toolhelp functions (Process32First and Process32Next). On Windows 2000/XP, use PSAPI library (EnumProcesses function)

Thanks
Please close this question.
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America 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