How to force the taskbar to refresh an app's shortcut icon

Viewed 35

The method below takes as one of the parameters the name of an icon (string newIcon) to update a shortcut in the Taskbar (currentLink.SetIconLocation(@$"C:\Meus Programas\_Ícones\{newIcon}", 0);).

But the icon image is not being changed immediately when the method is executed. Is there any way to force Explorer to refresh the shortcut icon?

 private void ChangeShortcutLinkTarget(string shortcutFullPath, string newTarget, string newIcon)
            {
                // Load the shortcut.
                Shell32.Shell shell = new Shell32.Shell();
                Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(shortcutFullPath));
                Shell32.FolderItem folderItem = folder.Items().Item(Path.GetFileName(shortcutFullPath));
                Shell32.ShellLinkObject currentLink = (Shell32.ShellLinkObject)folderItem.GetLink;

                // Assign the new path here. This value is not read-only.
                currentLink.Path = newTarget;
                currentLink.SetIconLocation(@$"C:\Meus Programas\_Ícones\{newIcon}", 0);

                // Save the link to commit the changes.
                currentLink.Save();

            }
0 Answers
Related