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_MA CHINE;
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(Val ue)
else begin
Result:=DefValue;
Reg.WriteString(Value, DefValue);
end;
finally
Reg.free;
end;
end;
called by
SomeString:=GetHKLocal('SO FTWARE', 'MYCompany\MYProgram\AValu e', '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.
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_MA
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(Val
else begin
Result:=DefValue;
Reg.WriteString(Value, DefValue);
end;
finally
Reg.free;
end;
end;
called by
SomeString:=GetHKLocal('SO
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
I will now write my own TRegistry descendant using the proper rights.
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.