Solved

Registry access rights

Posted on 1998-12-05
3
176 Views
Last Modified: 2010-04-04
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
Comment
Question by:Roadrunner100598
3 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1349382
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
 
LVL 7

Accepted Solution

by:
BlackMan earned 100 total points
ID: 1349383
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
 
LVL 1

Author Comment

by:Roadrunner100598
ID: 1349384
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now