TRegistry - why are some keys readable and others not?

I wrote the following code:

var
  MainForm: TMainForm;

const
  SRootKey = HKEY_LOCAL_MACHINE;
  SKey = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles';

implementation

{$R *.dfm}

{ TMainForm }

procedure TMainForm.GetKeys(OutList: TStrings);
var
  Reg: TRegistry;
begin
  OutList.BeginUpdate;
  try
    OutList.Clear;

    Reg := TRegistry.Create(KEY_READ);
    try
      Reg.RootKey := SRootKey;
      if (Reg.OpenKeyReadOnly(SKey)) and (Reg.HasSubKeys) then
      begin
        Reg.GetKeyNames(OutList);
        Reg.CloseKey;
      end;
    finally
      Reg.Free;
    end;
  finally
    OutList.EndUpdate;
  end;
end;

procedure TMainForm.btnScanClick(Sender: TObject);
begin
  GetKeys(ListBox1.Items);
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  GetKeys(ListBox1.Items);
end;

      

It doesn't do anything.

I can check the registry path (Windows 8.1), I even changed it SKey

for testing and no problem, but some keys like this return nothing.

I even tried running the program from Windows like Administrator

nothing else.

Is there anything else I need to change? To make certain keys available and others not?

+3


source to share


1 answer


Your process is 32 bit and you are running it on a 64 bit machine. So you fall under registry redirection .

The registry redirector isolates 32-bit and 64-bit applications by providing separate logical representations of certain parts of the WOW64 registry. The Registry Redirector intercepts 32-bit and 64-bit registry calls into their respective logical registry views and maps them to the appropriate location in the physical registry. The redirection process is transparent to the application. Thus, a 32-bit application can access registry data as if it were running on 32-bit Windows, even if the data is stored elsewhere on 64-bit Windows.

The key you are looking at

HKLM\SOFTWARE

      

redirected. From your 32-bit process, attempts to open this key are redirected to a 32-bit registry view, which is stored as an implementation detail in



HKLM\SOFTWARE\Wow6432Node

      

What you are trying to do here is access the 64 bit representation of the registry. To do this, you need to access an alternate registry view . This means passing a key KEY_WOW64_64KEY

when any keys are opened.

In Delphi, you can achieve this by including KEY_WOW64_64KEY

in flags, Access

or by including it in flags that you pass to the constructor.

Reg := TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);

      

Also, for that particular key, due to the security configuration of the registry for that key, you need to run with administrator privileges to open the key. Even if you only intend to read it.

+10


source







All Articles