Delete Registry Value - Delphi

DarkCoderSc personal avatar
DarkCoderSc

Jean-Pierre LESUEUR

// ...

procedure DeleteRegistryValue(const AHive : HKEY; const AKeyPath, AValueName : String);
begin
  var AKeyHandle : HKEY;
  var AResult := RegOpenKeyExW(AHive, PWideChar(AKeyPath), 0, KEY_SET_VALUE, AKeyHandle);
  if AResult <> ERROR_SUCCESS then
    raise EWindowsException.Create('RegOpenKeyW', AResult);
  try
    AResult := RegDeleteValueW(AKeyHandle, PWideChar(AValueName));
    if AResult <> ERROR_SUCCESS then
      raise EWindowsException.Create('RegDeleteValueW', AResult);
  finally
    RegCloseKey(AKeyHandle);
  end;
end;


// ...

begin
  try
    DeleteRegistryValue(HKEY_CURRENT_USER, 'Software\Test', 'Test Value');
  except
    on e : Exception do
      WriteLn(e.Message);
  end;

// ...

Creating and researching code snippets takes time and effort. You’re welcome to share them through your own platforms, but please don’t forget to credit the original author, here: Jean-Pierre LESUEUR.

no AI logo


Depends On


Created

December 2, 2025

Last Revised

December 2, 2025