1
{******************************************************************************
3
******************************************************************************}
5
Procedure TRegistry.SysRegCreate;
7
FStringSizeIncludesNull:=True;
10
Procedure TRegistry.SysRegfree;
15
Function PrepKey(Const S : String) : pChar;
24
Function RelativeKey(Const S : String) : Boolean;
27
Result:=(S='') or (S[1]<>'\')
31
function TRegistry.sysCreateKey(const Key: String): Boolean;
36
SecurityAttributes: Pointer; //LPSECURITY_ATTRIBUTES;
39
SecurityAttributes := Nil;
41
Result:=RegCreateKeyExA(GetBaseKey(RelativeKey(Key)),
45
REG_OPTION_NON_VOLATILE,
49
@Disposition) = ERROR_SUCCESS;
53
function TRegistry.DeleteKey(const Key: String): Boolean;
59
Result:=RegDeleteKeyA(GetBaseKey(RelativeKey(Key)),P)=ERROR_SUCCESS;
62
function TRegistry.DeleteValue(const Name: String): Boolean;
64
Result := RegDeleteValueA(fCurrentKey, @Name[1]) = ERROR_SUCCESS;
67
function TRegistry.SysGetData(const Name: String; Buffer: Pointer;
68
BufSize: Integer; var RegData: TRegDataType): Integer;
75
If RegQueryValueExA(fCurrentKey,P,Nil,
76
@RD,Buffer,lpdword(@BufSize))<>ERROR_SUCCESS Then
82
else if (RD=REG_EXPAND_SZ) then
83
Regdata:=rdExpandString
84
else if (RD=REG_DWORD) then
86
else if (RD=REG_BINARY) then
94
function TRegistry.GetDataInfo(const ValueName: String; var Value: TRegDataInfo): Boolean;
102
Result:=RegQueryValueExA(fCurrentKey,P,Nil,lpdword(@RegData),Nil,lpdword(@DataSize))=ERROR_SUCCESS;
105
Value.RegData := rdUnknown;
111
function TRegistry.GetKey(const Key: String): HKEY;
122
RegOpenKeyEx(GetBaseKey(Rel),PWideChar(WideString(S)),0,FAccess,Result);
124
RegOpenKeyEx(GetBaseKey(Rel),PChar(S),0,FAccess,Result);
129
function TRegistry.GetKeyInfo(var Value: TRegKeyInfo): Boolean;
131
winFileTime: Windows.FILETIME;
132
sysTime: TSystemTime;
134
FillChar(Value, SizeOf(Value), 0);
136
Result:=RegQueryInfoKeyA(CurrentKey,nil,nil,nil,lpdword(@NumSubKeys),
137
lpdword(@MaxSubKeyLen),nil,lpdword(@NumValues),lpdword(@MaxValueLen),
138
lpdword(@MaxDataLen),nil,@winFileTime)=ERROR_SUCCESS;
141
FileTimeToSystemTime(@winFileTime, @sysTime);
142
Value.FileTime := SystemTimeToDateTime(sysTime);
147
function TRegistry.KeyExists(const Key: string): Boolean;
155
FAccess:=KEY_QUERY_VALUE or KEY_ENUMERATE_SUB_KEYS or STANDARD_RIGHTS_READ;
156
KeyHandle:=GetKey(Key);
159
RegCloseKey(KeyHandle);
168
function TRegistry.LoadKey(const Key, FileName: string): Boolean;
174
function TRegistry.OpenKey(const Key: string; CanCreate: Boolean): Boolean;
179
Disposition: Integer;
180
SecurityAttributes: Pointer; //LPSECURITY_ATTRIBUTES;
183
SecurityAttributes := Nil;
188
Result:=RegCreateKeyExA(GetBaseKey(RelativeKey(Key)),P,0,'',
190
REG_OPTION_NON_VOLATILE,
191
fAccess,SecurityAttributes,Handle,
192
pdword(@Disposition))=ERROR_SUCCESS
196
Result:=RegOpenKeyExA(GetBaseKey(RelativeKey(Key)),
197
P,0,fAccess,Handle)=ERROR_SUCCESS;
202
function TRegistry.OpenKeyReadOnly(const Key: string): Boolean;
210
Result := RegOpenKeyExA(GetBaseKey(RelativeKey(Key)),P,0,KEY_READ,Handle) = 0;
212
fCurrentKey := Handle;
215
function TRegistry.RegistryConnect(const UNCName: string): Boolean;
220
function TRegistry.ReplaceKey(const Key, FileName, BackUpFileName: string): Boolean;
225
function TRegistry.RestoreKey(const Key, FileName: string): Boolean;
230
function TRegistry.SaveKey(const Key, FileName: string): Boolean;
235
function TRegistry.UnLoadKey(const Key: string): Boolean;
240
function TRegistry.ValueExists(const Name: string): Boolean;
246
Result:=GetDataInfo(Name,Info);
249
procedure TRegistry.CloseKey;
251
If (CurrentKey<>0) then
254
RegCloseKey(CurrentKey)
256
RegFlushKey(CurrentKey);
261
procedure TRegistry.ChangeKey(Value: HKey; const Path: String);
268
procedure TRegistry.GetKeyNames(Strings: TStrings);
278
if GetKeyInfo(Info) then
280
L:=Info.MaxSubKeyLen+1;
283
for I:=0 to Info.NumSubKeys-1 do
285
L:=Info.MaxSubKeyLen+1;
286
RegEnumKeyExA(CurrentKey,I,P,L,Nil,Nil,Nil,Nil);
287
Strings.Add(StrPas(P));
295
procedure TRegistry.GetValueNames(Strings: TStrings);
305
if GetKeyInfo(Info) then
307
L:=Info.MaxValueLen+1;
310
for I:=0 to Info.NumValues-1 do
312
L:=Info.MaxValueLen+1;
313
RegEnumValueA(CurrentKey,I,P,L,Nil,Nil,Nil,Nil);
314
Strings.Add(StrPas(P));
323
Function TRegistry.SysPutData(const Name: string; Buffer: Pointer;
324
BufSize: Integer; RegData: TRegDataType) : Boolean;
332
rdUnknown : RegDataType:=REG_NONE;
333
rdString : RegDataType:=REG_SZ;
334
rdExpandString : RegDataType:=REG_EXPAND_SZ;
335
rdInteger : RegDataType:=REG_DWORD;
336
rdBinary : RegDataType:=REG_BINARY;
339
Result:=RegSetValueExA(fCurrentKey,P,0,RegDataType,Buffer,BufSize)=ERROR_SUCCESS;
342
procedure TRegistry.RenameValue(const OldName, NewName: string);
346
InfoO,InfoN : TRegDataInfo;
351
If GetDataInfo(OldName,InfoO) and Not GetDataInfo(NewName,InfoN) then
358
L:=GetData(OldName,P,L,D);
359
If SysPutData(NewName,P,L,D) then
360
DeleteValue(OldName);
368
procedure TRegistry.SetCurrentKey(Value: HKEY);
370
fCurrentKey := Value;
373
procedure TRegistry.SetRootKey(Value: HKEY);