Jump to content
Tuts 4 You

[Delphi] Reload Registry Settings...


mAStEr pAIn

Recommended Posts

mAStEr pAIn
Posted

Hi Guys...

Hope someone can help me out with a problem in delphi programming.

First of all i'm coding in delphi since around 3 month.

I want to describe my prob a little bit more... I'm using windows 7 x64. In win7 and also in win vista you can add program links to the task bar. But you can only do this when the string "IsShortcut" is written in the windows registry. When this string exists you have on your desktop some "freeky" arrows on your links. So i made a little app to write and delete this string to the registry. For now so good. But you only see the changes take effect when you log off and on again. Or you do a complete system restart. And theres my problem. I know that its possible that windows reload this changes immediately without to be logged off and on again.

The simple code looks so...


procedure TForm1.Button1Click(Sender: TObject);
begin
RegAccess := TRegistry.Create(KEY_ALL_ACCESS);
try
RegAccess.RootKey := HKEY_LOCAL_MACHINE;
if RegAccess.OpenKey('SOFTWARE\Classes\lnkfile', True) then
RegAccess.WriteString('IsShortcut', ' ');
RegAccess.CloseKey;
if RegAccess.OpenKey('SOFTWARE\Classes\piffile', True) then
RegAccess.WriteString('IsShortcut', ' ');
RegAccess.CloseKey;
finally
RegAccess.Free;
Form2.Position := poMainFormCenter;
Form2.ShowModal;
end;
end;

I think the key to a solution is to use the "SendMessage" API with "WM_SettingChange". According to the MSDN Database the syntax is...

LRESULT WINAPI SendMessage( 
__in HWND hWnd,
__in UINT Msg,
__in WPARAM wParam,
__in LPARAM lParam );

So i implemented the function by this way...

SendMessage(HWND_Broadcast, WM_SettingChange, 0, 0);

To broadcast the "WM_SettingChange" message i got a tip from mazuki. Its needed to use the "SystemParametersInfo" function. I tested an implementation by this way...

SystemParametersInfo(SPI_SETICONS, 0, NULL, SPIF_SENDCHANGE);

But i still have no luck to get around this problem. Currently i have no idea what i could do more.

If its helpfull... I'm coding with Delphi 2010.

grEEtZ sILeNt heLLsCrEAm

Posted

Maybe running your tool "as Administrator" (<- use contextual menu to run it)?

Best regards

Nacho_dj

Posted

Delphi doesn't support 64 bit yet so your executable will only access the 32 bit side of the registry !

the settings you write won't be effective unless you run your application in a 32 bit OS

If you want windows to see the changed Registry settings, use C# or VB.NET and compile using AnyCPU settings

or use 64 bit of C++ compiler.

btw, 64 registry scanners use a driver to access the 32 bit side of the registry on Windows 64 so

it's not a new problem.

mAStEr pAIn
Posted

No. I found a solution...

I implemented the "SHChangeNotify" function.

MSDN Syntax...

void SHChangeNotify(
LONG wEventId,
UINT uFlags,
__in_opt LPCVOID dwItem1,
__in_opt LPCVOID dwItem2
);
SHCNE_ASSOCCHANGED

A file type association has changed. SHCNF_IDLIST must be specified in the uFlags parameter. dwItem1 and dwItem2 are not used and must be NULL.

I implemented it like this...


Uses ShlObjSHChangeNotify(SHCNE_ASSOCCHANGED, 0, nil, nil);

And this is working... :yahoo:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...