Link to home
Start Free TrialLog in
Avatar of Roadrunner100598
Roadrunner100598

asked on

Registry access rights

I have a problem with registry access on NT 4.0 machines that are logged in as users on a primary domain controller.

The following code should read an entry from HK_LOCAL_MACHINE and return a default value, if the key is not present - the key is then inserted with the default value.

function GetHKLocal(Key0, KeyRest, Value:string; DefValue:string):string;
var
  Reg : TRegistry;
begin
  { Read INI data from registry }
  Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_LOCAL_MACHINE;
  try
    Reg.OpenKey('\'+Key0, false); { Users may only insert keys above that level!      }
    Reg.OpenKey(KeyRest, true);   { Otherwise WinNt will raise an Registry Open Error }
    if Reg.ValueExists(Value) then
      Result:=Reg.ReadString(Value)
    else begin
      Result:=DefValue;
      Reg.WriteString(Value, DefValue);
    end;
  finally
    Reg.free;
  end;
end;

called by

  SomeString:=GetHKLocal('SOFTWARE', 'MYCompany\MYProgram\AValue', 'Default');

This runs fine under 95, NT4.0 (local), NT4.0(logged into workgroup) but on some (not all!) PCs it fails with an IO-Error on the Reg.WriteString method. The users have rights to access/edit the registry - I checked that via RegEdit.EXE.

Any ideas?


Thank you, Roadrunner.
Avatar of Madshi
Madshi

I can't check it, since I've only win95. But I can say one thing:

Please don't write:
  Reg.OpenKey('\'+Key0, false);
Better is:
  Reg.OpenKey(Key0,false);

Perhaps this solves your problem, probably not...  :-(

Please tell me if it helps.

Regards... Madshi.
ASKER CERTIFIED SOLUTION
Avatar of BlackMan
BlackMan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roadrunner100598

ASKER

Thanks a lot BlackMan, this will was exactly what I was looking for.

I will now write my own TRegistry descendant using the proper rights.