function GetStringValueFromRegistry(RootKey : HKEY; KeyName, ValueName : WideString;
var RequestedValue : WideString) : boolean;
var
Handle : HKEY;
Buffer : Pointer;
BufSize : Integer;
DataType : Integer;
ReturnValue : Integer;
begin
Result := false;
if RegOpenKeyExW(RootKey, PWideChar(KeyName), 0, KEY_QUERY_VALUE,
Handle) = ERROR_SUCCESS
then
begin
Buffer :=
nil;
BufSize := 0;
DataType := REG_SZ;
repeat
Inc(BufSize, 1024);
ReallocMem(Buffer, BufSize);
ReturnValue := RegQueryValueExW(
Handle, PWideChar(ValueName),
nil, @DataType, Buffer, @BufSize);
until ReturnValue <> ERROR_MORE_DATA;
if ReturnValue = ERROR_SUCCESS
then
begin
Result := true;
RequestedValue := WideString(PWideChar(Buffer));
end;
FreeMem(Buffer);
RegCloseKey(
Handle);
end;
end;
function SetStringValueInRegistry(RootKey : HKEY; KeyName, ValueName, Value : WideString) : boolean;
var
Handle : HKEY;
ReturnValue : Integer;
begin
Result := false;
if RegCreateKeyExW(RootKey, PWideChar(KeyName), 0,
nil, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE
or KEY_WRITE,
nil,
Handle,
nil) = ERROR_SUCCESS
then
begin
ReturnValue := RegSetValueExW(
Handle, PWideChar(ValueName), 0, REG_SZ, PWideChar(Value), (Length(Value) + 1) * 2);
result := ReturnValue = ERROR_SUCCESS;
RegCloseKey(
Handle);
end;
end;