Solved

Rebuilding the Windows Icon Cache

Posted on 2001-07-01
5
874 Views
Last Modified: 2007-12-19
Does anyone have any clues about how to programmatically rebuild the Icon Cache.
I am currently involved with developing an upgrade of a program. This new version has a new icon, so I want the program to be able to rebuild the Icon Cache when it is first installed so the old shortcuts get the new icon...

I don't want to delete the SHELLICONCACHE file. Anyone know how TweakUI does it???

Cheers,
Greg
0
Comment
Question by:gwhite012597
  • 3
5 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 6243366
hi,
you can use this procedure to rebuild the icons:

Regards Barry

uses registry;

procedure RebuildIcons;
var
  Registry: TRegistry;
  OldSize: integer;
 dwResult: cardinal;
const
  SShellIconSize = 'Shell Icon Size';
  Timeout = 1000;
begin
  Registry := TRegistry.Create;
  try
    if not Registry.OpenKey('Control Panel\Desktop\WindowMetrics', False)
then
      MessageBeep(0);
    if Registry.ValueExists(SShellIconSize) then
      OldSize := StrToInt(Registry.ReadString(SShellIconSize))
    else
      OldSize := 0;
    Registry.WriteString(SShellIconSize, IntToStr(OldSize + 1));
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
      SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, Timeout, dwResult);
    if OldSize > 0 then
      Registry.WriteString(SShellIconSize, IntToStr(OldSize))
    else
      Registry.DeleteValue(SShellIconSize);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
      SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, Timeout, dwResult);
    Registry.CloseKey;
  finally
    Registry.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RebuildIcons;
end;
0
 
LVL 17

Expert Comment

by:inthe
ID: 6243378
timeout may want to be longer (5000) maybe ..
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6243379
Uses ShlObj;

  SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_FLUSHNOWAIT or SHCNF_FLUSH or SHCNF_PATH,nil,nil);
  SHChangeNotify(SHCNE_UPDATEIMAGE,SHCNF_FLUSHNOWAIT or SHCNF_FLUSH or SHCNF_PATH,nil,nil);
0
 
LVL 17

Expert Comment

by:inthe
ID: 6243385
impressive ;-)
0
 

Author Comment

by:gwhite012597
ID: 6247958
Thanks for the help. Both answers are good. I think I prefer the two liner :) but I'm going split the points. Is that OK with you guys??

Cheers,
Greg
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 155
Create a path if not exists 7 89
Tvertscrollbox like a whatsapp layout delete messages 1 23
Breakpoint doesn't stop in my variable 3 30
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question