Solved

Rebuilding the Windows Icon Cache

Posted on 2001-07-01
5
864 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
automatically logging in via bde delphi 3 70
Working this component WebCopy with proxy, help 3 76
Print Graphic and Text to Epson TM-T88v 12 185
Working with hours 3 46
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

862 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now