Free Tool: Refresh the Desktop Programmatically
|
by Helge Klein on 11/22/2007 | 9 Comments | 13,455 Views
|
I recently had the requirement to refresh the Windows desktop after certain changes had been made to Explorer's registry entries. This seems simple at first: klick on any item on the desktop and then press F5. It wasn't, though. The registry changes would be made upon logon by a software installation agent. It was expected by the customer that the end user see the the effects of the change immediately without any user intervention. That sent me hunting for a solution on the internet. I came across many forum posts that showed that many others already had exactly the same requirement. Interestingly, none of the proposed solutions actually worked. Except for one, which I found at last.
What I Wanted to Change
As you may know Microsoft stripped the ability to enable display of an Internet Explorer icon on the desktop from Vista's GUI. However, it is very simple to add an IE icon to the desktop with a simple registry change:
Implementing this in a script was a no-brainer. What gave me a headache was this: how to convince Explorer to reread it's registry entries and actually display the thing without prompting the user to log off and on again.
How to Do it
The solution, once found, is simple, as always. There is an API function that tells the shell that file associations have changed:
SHChangeNotify (SHCNE_ASSOCCHANGED, 0, 0, 0);
SHCNE_ASSOCCHANGED is, by the way, defined as 0x8000000.
This effectively triggers a refresh of the desktop. And voilà, the IE icon appears.
Coding it
I suspect that this correct solution to the problem is so seldom mentioned on the internet because few people know how to operate a compiler. That is unfortunate and cannot be remedied by me. What I can do is provide a simple command line program that does nothing but call SHChangeNotify with the parameters quoted above.
You can find it here. I hope you find it useful.
DesktopRefresh.exe has been tested on Windows XP SP2 and Vista RTM. It should work on any Windows OS from NT 4.0 upward.
- ‹ previous
- 13 of 156
- next ›
+++ Your opportunity +++ Use Profile Migrator 2, the new sepago product that makes migrating user personalities between different platforms a breeze.! Download your free version now!
9 responses for "Free Tool: Refresh the Desktop Programmatically" |
Recent Articles
About the author
![]() |
Helge Klein IT-Architect Blogs about Windows, Terminal Services and other things |
Most viewed
| 155,208 Views |
Where is the Hosts File on Windows x64? |
| 83,072 Views |
Deleting a Local User Profile - Not as easy as one Might Assume |
| 53,089 Views |
Printer Driver Isolation in Windows 7 and Server 2008 R2 |








Nice tool, can be useful
Nice tool, can be useful indeed!
Thanks for sharing it.
Very nice solution! I think
Very nice solution! I think it's usefull for nearly every environment.
Thanks!
Udo
I'm not sure if this will
I'm not sure if this will work for this particular application, but we had an issue where we were trying to change users' wallpapers "on-the-fly" so that they would be branded according to their office location. We found a way to do this by updating the HKCU reg keys, then executing the following:
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
The result was an instant update of the user's wallpaper.
Perhaps you could try it and see if it works?
-SL
Shawn, The
Shawn,
The command
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
updates certain settings, like the wallpaper, for example. However, it does not work for the IE icon example I mentioned in the article.
[...] a description and
[...] a description and download link please go here. Print This Post « [...]
[...] Download the current
[...] Download the current version here. [...]
Thanks for posting this. I
Thanks for posting this. I now call SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST, 0, 0) from our applications installers. That is so much easier than the usual instructions that people put up about deleting iconcache.db
Hi, is the desktoprefresh.exe
Hi, is the desktoprefresh.exe available for 64 bits system? I wóuld like to use it in winpe X64 (no syswow available)
I just compiled a 64-bit
I just compiled a 64-bit version. You can find it here: http://www.sepago.de/d/downloads/desktoprefresh-x64/2639. I will update the tool's page soon.