Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to acces HKEY_LOCAL_MACHINE registry with user non admin?

Status
Not open for further replies.

PlutoDev

Programmer
Sep 21, 2002
25
ID
When using the TRegistry component under NT, a user with less than
"administrator" rights is unable to access information stored in the
HKEY_LOCAL_MACHINE. How can I work around this?

Thank's in advance
 
You'll have to access HKEY_CURRENT_USER - AFAIK, there's no way to get around this piece NT security and, if you think about viruses and trojans, you really don't want there to be a way around it.

-Dell
 
I agree with hilfy, your program should be able to read the LOCAL_MACHINE keys but not write to them unless the user has supervisor rights.
Dont forget that these rights are default on a new install of Windows so a stand alone machine should not be problem for your application.
If the machine is in a secure network but do you really need want users without access rights to install/alter programs? this is the reason windows NT/XP blocks access to these keys.
My own programs write registration info to HKLM but I dont consider this a problem.


Steve
Be excellent to each other and Party on!
 
check in regedit if the user has any rights to HKLM.
normally you should have read only rights. if this is the case, the code below should work (taken from delphi help) :

Code:
function GetRegistryValue(KeyName: string): string;
var
  Registry: TRegistry;
begin
  Registry := TRegistry.Create(KEY_READ);
  try
    Registry.RootKey = HKEY_LOCAL_MACHINE;
    // False because we do not want to create it if it doesn't exist
    Registry.OpenKey(KeyName, False); 
    Result := Registry.ReadString('VALUE1');
  finally
    Registry.Free;
  end;
end;

cheers

--------------------------------------
What You See Is What You Get
 
If you where to use OpenKeyReadonly(), or change TRegistry.Access to KEY_READ before caling OpenKey(), then it won't moan if you don't have write access-rights. If this also fails, either the key doesn't exist, or you don't even have these read-rights. (lookup TRegistry.Access in Delphi help)

HTH
TonHu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top