Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a 32-bit program read the "real" 64-bit version of the registry?

I'm trying to read HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run with OpenKeyReadOnly, and GetValueNames, but it's returning values from HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run instead.

How can I read the 64-bit values instead of from a redirect to the 32-bit key?

The program was run as an administrative account. I also tried RegOpenKeyEx and RegEnumValue.

I'm using Delphi 2010.

like image 872
Gu. Avatar asked Mar 30 '11 22:03

Gu.


People also ask

How do 32-bit programs run on 64 systems?

The 64-bit versions of Windows don't provide support for 16-bit binaries or 32-bit drivers. Programs that depend on 16-bit binaries or 32-bit drivers can't run on the 64-bit versions of Windows unless the program manufacturer provides an update for the program.

Can a 32bit program run on 64-bit?

Can I run 32-bit programs on a 64-bit computer? Most programs made for the 32-bit version of Windows will work on the 64-bit version of Windows except for most Antivirus programs. Device drivers that are made for the 32-bit version of Windows will not work correctly on a computer running a 64-bit version of Windows.

How do I change my registry from 32-bit to 64-bit?

Press SHIFT+F4 on your keyboard and select the components of the 64-bit registry values. Right-click one of them and select the "Properties" menu. In the "Edit Component Properties" dialog set the Condition field to VersionNT64. Tick the option 64-bit Component.


1 Answers

you must use the KEY_WOW64_64KEY value when open the Registry with the TRegistry class.

from MSDN :

KEY_WOW64_64KEY Indicates that an application on 64-bit Windows should operate on the 64-bit registry view. This flag is ignored by 32-bit Windows.

This flag must be combined using the OR operator with the other flags in this table that either query or access registry values.

try this sample app.

{$APPTYPE CONSOLE}

uses
  Windows,
  Classes,
  registry,
  SysUtils;


procedure ReadRegistry;
var
  Registry: TRegistry;
  List    : TStrings;
begin
  Registry := TRegistry.Create(KEY_WRITE OR KEY_WOW64_64KEY);
  //Registry := TRegistry.Create(KEY_READ OR KEY_WOW64_64KEY);
  List     := TStringList.Create;
  try
    Registry.RootKey := HKEY_LOCAL_MACHINE;
    if Registry.OpenKeyReadOnly('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run') then
    begin
       Registry.GetValueNames(List);
       Writeln(List.Text);
    end;
    Registry.CloseKey;
  finally
    Registry.Free;
    List.Free;
  end;
end;

begin
  try
   ReadRegistry();
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
  Readln;
end.
like image 92
RRUZ Avatar answered Oct 14 '22 17:10

RRUZ