How to check if a registry key exists and exit setup

I am trying to make an installation file to fix a previous program. The setting should be able to check whether the previous program is installed or not.

This is my unsuitable code.

 
[Code]
function GetHKLM() : Integer;

begin
 if IsWin64 then
  begin
    Result := HKLM64;
  end
  else
  begin
    Result := HKEY_LOCAL_MACHINE;
  end;
end;

function InitializeSetup(): Boolean;
var
  V: string;
begin
  if RegKeyExists(GetHKLM(), 'SOFTWARE\ABC\Option\Settings')
  then
    MsgBox('please install ABC first!!',mbError,MB_OK);
end;

My condition

  • should check 32- or 64-bit windows for RegKeyExists
  • If the previous program is not installed, display an error message and do not run the installation program, but continue the process.

How to change the code?
Thank you in advance.

** Update for fix problem Wow6432Node. I am trying to change my code

[Code]
function InitializeSetup: Boolean;
begin
  // allow the setup to continue initially
  Result := True;
  // if the registry key based on current OS bitness doesn't exist, then...
if IsWin64 then
begin
 if not RegKeyExists(HKLM, 'SOFTWARE\Wow6432Node\ABC\Option\Settings') then
  begin
   // return False to prevent installation to continue
   Result := False;
   // and display a message box
   MsgBox('please install ABC first!!', mbError, MB_OK);
  end

  else
   if not RegKeyExists(HKLM, 'SOFTWARE\ABC\Option\Settings' then
    begin
    // return False to prevent installation to continue
    Result := False;
    // and display a message box
    MsgBox('please install ABC first!!', mbError, MB_OK);
   end
  end;
end;
+4
source share
1 answer

- Wow6432Node , RegEdit.

32- . , Windows 32- 64-; .

:

[Code]
function InitializeSetup: Boolean;
begin
  // allow the setup to continue initially
  Result := True;
  if not RegKeyExists(HKLM, 'SOFTWARE\ABC\Option\Settings') then
  begin
    // return False to prevent installation to continue
    Result := False;
    // and display a message box
    MsgBox('please install ABC first!!', mbError, MB_OK);
  end;
end;
+3

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


All Articles