Registry is a very vital part in the Windows. Because of its importance, a lot of viruses and hacking programs that use the registry as part of his illegal operations. In the present article, I’ll take playing around with the registry for a moment.
We start by declaring the Registry unit in the Uses, looks like:
Uses Registry;
It’s simple, isn’t it?. Go on. The registry data type can be:
- Binary
- String
- DWord
- Boolean
With different data types, then writing to the registry will use a different function. The following description will explain how to write each data type before.
A. Writing Binary Data
- Instantiate the class of type Registry.
instantiating class must be preceded by declaring a variable as TRegistry. In the example below, the variable is the reg:var
reg : TRegistry;
i : integer;
DataKey : array of byte;
info : TRegDataInfo;begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CURRENT_USER;
………………………………………………………….. - Open registry
Example:
reg.OpenKey(’Control PanelAppearanceSchemes’,true);OpenKey command takes two parameters. The first parameter is a subkey of the registry, while the second parameter declares whether allowed to make a key if the key is not found.
- Write registry
Example:
DataKey[0] := $10;
reg.WriteBinaryData(’Aubergine’,pointer(DataKey)^, info.DataSize); - Close registry for saving all data that is wrote
reg.CloseKey;
- Destroy object from memory
FreeAndNil(reg);
B. Read Binary Data
- Instantiate the class of type Registry.
instantiating class must be preceded by declaring a variable as TRegistry. In the example below, the variable is the reg:var
reg : TRegistry;
i : integer;
DataKey : string;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CURRENT_USER;
………………………………………………………….. - Open registry
Example:
reg.OpenKey(’Control PanelAppearanceSchemes’,true); - Read registry
Example:
reg.ReadBinaryData(’TempatData’, DataKey, sizeof(DataKey));
ShowMessage(DataKey); - Close registry. Without it, data is not saved
reg.CloseKey;
- Releasing memory from object
FreeAndNil(reg);
C. Writing String Data
Below, I give example for writing autostart your program when windows
- Instantiate the class of type Registry.
instantiating class must be preceded by declaring a variable as TRegistry. In the example below, the variable is the reg:var
reg : TRegistry;
i : integer;
DataKey : string;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
………………………………………………………….. - Open registry
Example:
reg.OpenKey(’SoftwareMicrosoftWindowsCurrentVersionRun’,true); - Write this
Example:
reg.WriteString(’MyProgram’,'C:MyFolderProgramMyProgram.exe’); - Close registry object
reg.CloseKey;
- Destroy object
FreeAndNil(reg);
D. Read String Data
- Instantiate the class of type Registry.
instantiating class must be preceded by declaring a variable as TRegistry. In the example below, the variable is the reg:var
reg : TRegistry;
i : integer;
DataKey, IsiReg : string;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
……………………………………………………………….. - Open registry
Example:
reg.OpenKey(’SoftwareMicrosoftWindowsCurrentVersionRun’,true); - Read registry:
Example:
IsiReg := reg.ReadString(’MyProgram’);
ShowMessage(IsiReg); - Close registry
reg.CloseKey;
- Erase object from memory
FreeAndNil(reg);
E. Writing DWord Data
The explanation below is about the writing of data type DWORD in the registry by taking samples in order to disable registry.
- Instantiate the class of type Registry.
instantiating class must be preceded by declaring a variable as TRegistry. In the example below, the variable is the reg:var
reg : TRegistry;
i : integer;
DataKey, IsiReg : string;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CURRENT_USER;
……………………………………………………………….. - Open registry
Example:
reg.OpenKey(’SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem’,true); - Write registry
Example:
reg.WriteInteger(’DisableRegistryTools’,00000001); - Close registry
reg.CloseKey;
- Destroy object
FreeAndNil(reg);
F. Read DWord Data
- Instantiate the class of type Registry.
instantiating class must be preceded by declaring a variable as TRegistry. In the example below, the variable is the reg:var
reg : TRegistry;
i : word;
DataKey : integer;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CURRENT_USER;
………………………………………………………… - Open registry
Example:
reg.OpenKey(’SoftwareMicrosoftWindowsCurrentVersionPoliciesSystem’,true); - Read registry
Example:
i := reg.ReadInteger(’DisableRegistryTools’);
ShowMessage(IntTostr(i)); - For saving data, we have to close registry
reg.CloseKey;
- Always destroy object after using it
FreeAndNil(reg);
G. Write Boolean Data
- Instantiate the class of type Registry.
instantiating class must be preceded by declaring a variable as TRegistry. In the example below, the variable is the reg:var
reg : TRegistry;
i : word;
DataKey : integer;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CURRENT_USER;
………………………………………………………… - Open registry
Example:
reg.OpenKey(’SubKey’,true); - Read registry
Example:
reg.WriteBool(’DisableRegistryTools’); - For saving data, we have to close registry
reg.CloseKey;
- Always destroy object after using it
FreeAndNil(reg);
H. Read Boolean Data
- Instantiate the class of type Registry.
instantiating class must be preceded by declaring a variable as TRegistry. In the example below, the variable is the reg:var
reg : TRegistry;
YesNo : Boolean;
DataKey : integer;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CURRENT_USER;
………………………………………………………… - Open registry
Example:
reg.OpenKey(’SubKey’,true); - Read registry
Example:
YesNo := reg.ReadBool(’DisableRegistryTools’);if YesNo then
ShowMessage(’YES’)
else
ShowMessage(’NO’); - For saving data, we have to close registry
reg.CloseKey;
- Always destroy object after using it
FreeAndNil(reg);










