When I change the icon in my shortcut, why doesn’t it update on the screen?

A customer was having trouble updating the icon in one of their shortcuts. Here's what they shared with us:

    i_shell_link->SetIconLocation(icon_file.value().c_str(), 0);

"Changing the icon from the shortcut property sheet works, but it's not working from our code. Is the shortcut property sheet using a different API from IShell­Link::Set­Icon­Location? In desperation, we added


but that didn't help. Did we get the flags to SHChange­Notification wrong?"

The property sheet does use the IShell­Link::Set­Icon­Location method to change the shortcut icon. What the customer forgot was to save their changes!

    i_persist_file->Save(NULL, TRUE);

where i_persist_file is the IPersist­File that they used to load the shortcut, or they can use Query­Interface to get a new pointer.

The SHCNE_ASSOC­CHANGED notification is unnecessary, and in fact it's overkill. That's like saying, "I want to change the color of my sofa, so I'm going to demolish my house, rebuild it, and then refurnish it with a new sofa."

If you want to send a notification to say, "Hey, I updated this file, please go refresh any data you have cached about it," you can do a

    SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, fullpath, NULL);
Comments (10)
  1. Mason Wheeler says:

    I can make sense of most of the mnemonics, but what in the world is a SHCNE?

  2. SHell Change Notify Event, maybe?  Or Enum.

  3. ErikF says:

    @Mason Wheeler: Given the wording in the documentation for the function (msdn.microsoft.com/…/bb762118(v=vs.85).aspx), I'd say it's SHChangeNotify event (SHCNF is a SHChangeNotify flag.)

  4. Christian says:

    @Mason Wheeler: Just a guess (after looking in MSDN what's the name of the first parameter): *SH*ell*C*hange*N*otify*E*vent.

  5. skSdnW says:

    I have observed that SHCNE_ASSOCCHANGED will sometimes refresh things not really related to file associations. For example, it seems to update shortcut icons pinned to the taskbar (*1). It is no wonder people might have had some success with it in certain scenarios and use it as a last resort to try to fix icon cache issues.

    *1: I guess this could be explained by .lnk files having a icon handler shell extension that makes those icons in the shell imagelist per-instance and receiving this event refreshes the imagelist?

  6. Sarkie says:

    Is this also related to IconCache.db  ?

  7. richardguk says:

    Minor HTML typo in blogpost: "…Did we get the flags to  ‹COE›SHChange­Notification‹/CODE› wrong?" ("COE" tag for "CODE", breaks Atom preview in Feedly.) Muphry's Law?

  8. skSdnW says:

    @Sarkie: Not really. The issue was that the changes made to the shortcut only exist in memory until you call the Save method.

    The shell imagelist is cached in that file and can become outdated or have other issues but it is not tied directly to shortcut icons, you can for example ask SHGetFileInfo to give you a HICON or query IShellLink for the icon location and manually extract bypassing the shell imagelist. Explorer and Open/Save dialogs use the shell imagelist (implementation detail) and will sometimes fail to display the correct icon.

  9. xpclient says:

    Right click a shortcut on Quick Launch, Properties, change its icon, click OK/Apply. Gets updated instantly. But Shift+right click a pinned taskbar shortcut, Properties, change its icon, click OK/Apply. Icon doesn't change. After using a third party tool I found that probably sends a SHCNE, all pinned taskbar icons are refreshed/updated instantly. Why is this?

Comments are closed.

Skip to main content