Problems reading registry with Delphi 7 on Windows 7 64 bit

I think this question has already been asked, but I could not find a solution that works for me. I am using Delphi 7 under Windows 7 Ultimate, 64 bit. Actually, I started writing the application under 32-bit OS, but then I changed the PC, so now it is 64. In my program, I use the registration process with the license identifier generated from the PROGID value for Windows. Unfortunately, it does not read the value, it looks like it is looking in another folder, it may be redirected by Windows from 64 to 32 bits of the registry. You can help? This is the code I'm using:

 Registry := TRegistry.Create(KEY_READ OR $0100);
    try
      Registry.Lazywrite := false;
      Registry.RootKey := HKEY_LOCAL_MACHINE;
      if CheckForWinNT = true then
       Begin
       if not Registry.OpenKeyReadOnly('\Software\Microsoft\Windows NT\CurrentVersion') then showmessagE('cant open');
       end
      else
        Registry.OpenKeyReadOnly('\Software\Microsoft\Windows\CurrentVersion');
      result := Registry.ReadString('ProductID'); 
      Registry.CloseKey;
    finally
      Registry.Free;
    end; // try..finally

Do you also know how to find out if a program works under a 64-bit or 32-bit computer in Delphi 7?

+3
4

, . Registry ReadString Windows 7 Delphi 7.

, , $0100 TRegistry.Create. , OpenKeyReadOnly, Access KEY_READ, KEY_READ or $0100 .

OpenKey OpenKeyReadOnly, reset Access.

+12

Delphi 7 , 64- :

function Is64BitOS: Boolean;
type
  TIsWow64Process = function(Handle:THandle; var IsWow64 : BOOL) : BOOL; stdcall;
var
  hKernel32 : Integer;
  IsWow64Process : TIsWow64Process;
  IsWow64 : BOOL;
begin
  // we can check if the operating system is 64-bit by checking whether
  // we are running under Wow64 (we are 32-bit code). We must check if this
  // function is implemented before we call it, because some older versions
  // of kernel32.dll (eg. Windows 2000) don't know about it.
  // see http://msdn.microsoft.com/en-us/library/ms684139%28VS.85%29.aspx
  Result := False;
  hKernel32 := LoadLibrary('kernel32.dll');
  if (hKernel32 = 0) then RaiseLastOSError;
  @IsWow64Process := GetProcAddress(hkernel32, 'IsWow64Process');
  if Assigned(IsWow64Process) then begin
    IsWow64 := False;
    if (IsWow64Process(GetCurrentProcess, IsWow64)) then begin
      Result := IsWow64;
    end
    else RaiseLastOSError;
  end;
  FreeLibrary(hKernel32);
end;

( , )

, KEY_WOW64_64KEY ($ 0100), 64- . 32- , KEY_WOW64_32KEY ($ 0200).

+9

, 64- ( , 64- ), .

+1

, delphi 7, , , .. Key_Read , .

Delphi 2010, Key_Read.

Here is my part of my source that works:

//Search registry

reg:=TRegistry.Create(KEY_READ);

  with reg do begin

    try
      RootKey := HKEY_LOCAL_MACHINE;
      if OpenKey('\SOFTWARE\Wow6432Node\Blizzard Entertainment\World of Warcraft',false) then
        begin
          memo.Lines.Add('HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Blizzard Entertainment\World of Warcraft - exists');
          wowdir1 := readstring('InstallPath');
          memo.Lines.Add('InstallPath - ' + wowdir1);
          newline;
          closekey;
        end;
      if OpenKey('\SOFTWARE\Wow6432Node\Blizzard Entertainment\World of Warcraft',false) then
        begin
          memo.Lines.Add('HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Blizzard Entertainment\World of Warcraft - exists');
          wowdir2 := readstring('GamePath');
          memo.Lines.Add('GamePath - ' + wowdir2);
          newline;
          wowdir1 := readstring('');
          closekey;
        end;
      if OpenKey('\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\World of Warcraft',false) then
         begin
          memo.Lines.Add'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\World of Warcraft - exists');
          wowdir3 := readstring('InstallLocation');
          memo.Lines.Add('InstallLocation - ' + wowdir3);
          newline;
          wowdir1 := readstring('');
          closekey;
        end;
    finally
     reg.Free;
    end;

I tried the other Keys that appear here, and found that I did not need KEY_WOW64_64KEY or KEY_WOW64_32KEY. This must be a bug that was fixed in Delphi 2010.

+1
source

Source: https://habr.com/ru/post/1746140/


All Articles