Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reloading the Registry

Posted on 1999-07-06
11
Medium Priority
?
533 Views
Last Modified: 2010-04-04
Win 95/98/NT: After changing file associations via code. I need to reload the registry so that my default icon has imediate effect within the current windows session. The changes to the registry have proved easy enough, but how do I reload with my new settngs without forcing a reboot? Thanks
0
Comment
Question by:PJLeyther
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
11 Comments
 

Author Comment

by:PJLeyther
ID: 1386682
Edited text of question.
0
 
LVL 1

Expert Comment

by:simoraikov
ID: 1386683
The only way to reload registry is to reboot
0
 
LVL 4

Expert Comment

by:Radler
ID: 1386684
To the shell refresh the changes try

SendMessage( HND_BROADCAST, WM_SETTINGSCHANGE, 0, 0 );
is very important the estability of explorer use
WaitForInputIdle with the shell app
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:simoraikov
ID: 1386685
The only way to reload registry is to reboot
0
 
LVL 15

Expert Comment

by:simonet
ID: 1386686
That's not it.

If that doesn't work, reject the answer and I'll post some working code that will let you force a refresh of the shell icons.

Alex
0
 
LVL 17

Expert Comment

by:inthe
ID: 1386687


0
 

Author Comment

by:PJLeyther
ID: 1386688
Thanks Radler for your quick response but I'm afraid
SendMessage( HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0 );
doesn't seem to work.

The icon for my association doesn't change until either a reboot or a specific set amount of time (on this last point I am only surmising!?).

0
 

Author Comment

by:PJLeyther
ID: 1386689
Thanks simoraikov for your quick response. I really don't want to reboot the machine.

In File Explorer-View-Folder Options-File Types after a change of file association there is an imediate effect. I need to find this message.
0
 
LVL 15

Accepted Solution

by:
simonet earned 400 total points
ID: 1386690
PJLeyther, what you need is not to reload the Registry, but simply refresh the icon cache, so the newly created icon association will be used. The procedure below does exactly that, without having to reboot the machine or anything. It just forces the icon cache to be refreshed.


procedure RebuildIcons;
var
  Registry: TRegistry;
  OldSize: integer;
{$IFDEF VER120}
  dwResult: cardinal;
{$ELSE}
  dwResult: integer;
{$ENDIF}    
const
  SShellIconSize = 'Shell Icon Size';
  Timeout = 10000; // Ten seconds
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;

I compiled the above with Delphi 4 and ran on Windows 95a. It worked *great*. If you have trouble with the line with SendMessageTimeout, just change the type of dwResult (to integer, cardinal or longint).

Let me know how it went.

Yours,

Alex
Athena's Place: http://www.bhnet.com.br/~simonet
0
 

Author Comment

by:PJLeyther
ID: 1386691
Thanks simonet(Alex) the points are yours.

As an extra note there is an interim update of files without icons, after which the desired result is displayed. Any ideas.

Thanks again

Paul

0
 

Expert Comment

by:pingouyn
ID: 13664235
Hi!
I found an almost identical code for VB6 in order to refresh icons.  I tried it and it worked, but the only thing is that it also looses the desktop icon positions under WinXP (it works fine with Win2K).  I tried to lock the desktop but still with no success (Call LockWindowUpdate(GetDesktopWindow())).

Has anyone got any idea?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

704 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