当前位置 : 主页 > 编程语言 > delphi >

inno-setup – 如何检查注册表项是否存在并退出设置

来源:互联网 收集:自由互联 发布时间:2021-06-23
我尝试制作安装文件以修补以前的程序.设置必须能够检查是否安装了以前的程序. 这是我无法使用的代码 [Code]function GetHKLM() : Integer;begin if IsWin64 then begin Result := HKLM64; end else begin Resul
我尝试制作安装文件以修补以前的程序.设置必须能够检查是否安装了以前的程序.

这是我无法使用的代码

 

[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;

我的病情是

>必须检查RegKeyExists的32位或64位窗口
>如果未安装以前的程序,则显示错误消息并退出安装程序,否则继续进程.

如何修改代码?
先感谢您.

**更新修复Wow6432Node问题.我尝试修改我的代码

[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;
问题中更新的代码是错误的 – 除了在RegEdit中查看路径之外,你永远不应该使用Wow6432Node.

从您描述的行为来看,您实际上正在寻找一个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;
网友评论