Skip to content

Instantly share code, notes, and snippets.

@segevfiner
Last active November 19, 2021 17:59
Show Gist options
  • Save segevfiner/f3a8b781a1ad4020fb6dd82ac3225e65 to your computer and use it in GitHub Desktop.
Save segevfiner/f3a8b781a1ad4020fb6dd82ac3225e65 to your computer and use it in GitHub Desktop.
Refresh the Windows icon cache
<#
.SYNOPSIS
Refresh the Windows icon cache.
.DESCRIPTION
Refresh the Windows icon cache. Some versions of Windows had the icon cache become corrupted occasionally,
showing the wrong icon for programs. This script will fix it by requesting that it be rebuilt.
.INPUTS
None.
.OUTPUTS
None.
#>
$signature = @"
public const int SHCNE_ASSOCCHANGED = 0x08000000;
public const uint SHCNF_IDLIST = 0x0000;
[DllImport("shell32.dll")]
public static extern void SHChangeNotify(int wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
"@
$RefreshIcons = Add-Type -MemberDefinition $signature -Name RefreshIcons -Namespace RefreshIcons -PassThru
$RefreshIcons::SHChangeNotify($RefreshIcons::SHCNE_ASSOCCHANGED, $RefreshIcons::SHCNF_IDLIST, [IntPtr]::Zero, [IntPtr]::Zero)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment