Free Tool: Refresh the Desktop Programmatically

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:

[HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerHideDesktopIconsNewStartPanel]
"{871C5380-42A0-1069-A2EA-08002B30309D}"=dword:00000000

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.

DesktopRefresh.exe has been tested on Windows XP, Vista and Windows 7. It should work on any Windows OS from NT 4.0 upward.

Download

DesktopRefresh, 1.0, x86 (recommended for most).

DesktopRefresh, 1.0, x64

Comments

Related Posts

Free Tool - List Registry Links (REG_LINK)

Recently I got into a very interesting discussion with my colleague Nicholas Dille on various aspects of Windows x64. One question he brought up was especially intriguing: knowing about registry redirection, it is not astonishing to find that the 32-bit version of the registry key HKLM\Software\Classes (aka HKCR) gets to be HKLM\Software\Classes\Wow6432Node. But there is also HKLM\Software\Wow6432Node\Classes!? How can there be two different Wow6432Node 32-bit keys for one 64-bit key?
Helge's Tools

Latest Posts

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In the first post, I showed how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In this second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In this first post, I’m showing how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In a second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware