Solved

Registry access rights

Posted on 1998-12-05
3
182 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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