Recent

Author Topic: Reading registry as restricted user  (Read 6679 times)

Eclipticon

  • Jr. Member
  • **
  • Posts: 51
Reading registry as restricted user
« on: May 15, 2011, 05:59:07 pm »
Hi,

I am readings strings from the registry (using TRegistry) ... code like this works like a charm with an admin account, but returns an empty string when run by a restricted user:

Code: [Select]
procedure TForm1.Button3Click(Sender: TObject);
var
  ARegistry: TRegistry;
begin
  ARegistry := TRegistry.Create;
  ARegistry.RootKey := HKEY_LOCAL_MACHINE;
  ARegistry.OpenKey('\Software\Microsoft\Windows NT\CurrentVersion', False);
  Caption := ARegistry.ReadString('ProductId');
  ARegistry.Free;
end;

I can, however, access the value w/o problems in registry editor. Can anyone provide me with an explanation/solution?

Thanks!
Lazarus 1.2.4 on Win XP/7 Virtual Machine

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Reading registry as restricted user
« Reply #1 on: May 15, 2011, 06:05:34 pm »
Try using OpenKeyReadOnly instead of just OpenKey

Eclipticon

  • Jr. Member
  • **
  • Posts: 51
Re: Reading registry as restricted user
« Reply #2 on: May 15, 2011, 06:25:03 pm »
I tried, and it works. Thank you.
Lazarus 1.2.4 on Win XP/7 Virtual Machine

 

TinyPortal © 2005-2018