Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Registry access rights

Posted on 1998-12-05
3
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

647 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