Menggunakan Registry Di Delphi

Farihin Muhamad
0
uses Registry;

 Procedure YourProc();
 var R:TRegistry;
 begin
 R:= TRegistry.Create;
 try
 R.RootKey:= HKEY_LOKAL_MACHINE;
 R.OpenKey('Software\YourAppName\Server', true);
 R.WriteString('KeyValue', 'Value');
 Edit1.Text:= R.ReadString('ValName');
 finally R.Free
 end;
 end;



uses registry;
 procedure TForm1.FormCreate(Sender: TObject) ;
 var
 reg:TRegistry;
 begin
 reg:=TRegistry.Create;
 with reg do begin
 try
 if OpenKey('\Control Panel\desktop', False) then begin
 //change wallpaper and tile it
 reg.WriteString ('Wallpaper','c:\windows\CIRCLES.bmp') ;
 reg.WriteString ('TileWallpaper','1') ;
 //disable screen saver//('0'=disable, '1'=enable)
 reg.WriteString('ScreenSaveActive','0') ;
 //update changes immediately
 SystemParametersInfo (SPI_SETDESKWALLPAPER,0, nil,SPIF_SENDWININICHANGE) ;
 SystemParametersInfo (SPI_SETSCREENSAVEACTIVE,0, nil,SPIF_SENDWININICHANGE) ;
 end
 finally
 reg.Free;
 end;
 end;
 end;



The Delphi TRegistry function CreateKey fails when the user is not logged in with administrative rights.
The cause of this problem is that by default Delphi opens the Windows registry with security access of KEY_ALL_ACCESS.
Even the Delphi function OpenKeyReadOnly opens the registry with the security access value KEY_ALL_ACCESS.

This is a major problem since you should store shared information about your program in HKEY_LOCAL_MACHINE (HKLM)
so all users of the computer have access to the settings. However, especially on a network users should never be setup as administrators.
To get around this problem when your program needs to access values in the registry,
you can use the standard Windows API functions RegOpenKeyEx, RegQueryValueEx, and RegCloseKey.


Disclaimer: I found this article over the internet, please inform me if you're the owner so i can put you to this article as credit/the owner.
Tags:

Post a Comment

0Comments

Post a Comment (0)