Aymeric on Software

Because we needed another of these blogs...

Force Windows to Refresh the Desktop (and Start Menu)

Today I learned a new trick.

When you programmatically delete a shortcut from the Desktop folder Windows is “generally” smart enough to update the Desktop and the “recently used programs” section of the Start Menu. But sometimes it does not work and you are left with a “ghost” icon.

As a regular end user, you can hit the F5 key to force a refresh of the Desktop, but for the Start Menu you are left with no alternative than killing/restarting explorer.exe.

I was looking for a better solution for a custom installer application. And after a lot of MSDN scattering and googling around, Eureka, I finally found a magic incantation to programmatically force a refresh of the Desktop.

1
SHChangeNotify (SHCNE_ASSOCCHANGED, 0, 0, 0);