Delphi – Tregistry – Why is some keys readable and some keys are not available?

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.For mCreate(Sender: TObject);
begin
GetKeys(ListBox1.Items);
end;

This doesn’t seem to do anything.

I can verify the registry path (Windows 8.1), I even changed the SKey for testing without any problems, but some keys like this did not return anything.

I even tried to download from Windows runs the program, but it still doesn’t.

Is there anything else I need to change? What makes some keys readable and others unreadable?

Your process is 32-bit, and you are running it on a 64-bit computer. Therefore, you Need to comply with registry redirection.

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

The key you are following

< /p>

HKLM\SOFTWARE

Redirected. In your 32-bit process, trying to open this key will be redirected to the 32-bit view of the registry, which is stored as implementation details In

HKLM\SOFTWARE\Wow6432Node

What you have to do here is to access the 64-bit view of the registry. For this, you need to access an alternate registry view. This means passing the KEY_WOW64_64KEY key when opening any key.

In Delphi, you can pass Include KEY_WOW64_64KEY in the Access flag, or include it in the flag passed to the constructor.

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

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

pre>

The most important thing is that for this specific key, due to the registry security configuration of this key, you need to run with administrator privileges to open the key. Even if you only intend to read it.

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.En dUpdate;
end;
end;

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

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

This doesn't seem to do anything.

I can verify the registry path (Windows 8.1), I even changed the SKey for testing without any problems, but some keys like this did not return anything.

I even tried to run the program from Windows as an administrator, but still nothing.

Is there anything else I need to change? What makes some keys readable and others unreadable?

Your process is 32-bit and you are running it on a 64-bit computer. Therefore, you need to comply with registry redirection.

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

The key you are following

HKLM\SOFTWARE

Redirected. In your 32-bit process, trying to open this key will redirect to the 32-bit view of the registry, which is stored as an implementation detail in

HKLM\SOFTWARE\Wow6432Node

What you are going to do here is to access the 64-bit view of the registry. For this, you need to access an alternate registry view. This means passing when opening any key KEY_WOW64_64KEY key.

In Delphi, you can do this by including KEY_WOW64_64KEY in the Access flag, or by including it in the flag passed to the constructor.

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

Most importantly, for this specific key, due to the registry security configuration of this key, you need to run with administrator privileges To open the key. Even if you only plan to read it.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3113 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.