[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

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.
0
Roadrunner100598
Asked:
Roadrunner100598
1 Solution
 
MadshiCommented:
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.
0
 
BlackManCommented:
The problem is that the OpenKey uses KEY_ALL_ACCESS, which includes the CREATE_LINK permission. This permission is only granted to Administrators. There is an Inprise article about it at http://www.inprise.com/devsupport/delphi/qanda/1307.html
0
 
Roadrunner100598Author Commented:
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now