Inno setup 需要有关Inno安装脚本的帮助-检查jre安装中的问题

Inno setup 需要有关Inno安装脚本的帮助-检查jre安装中的问题,inno-setup,Inno Setup,我正在使用下面的脚本安装一个Java程序。这个脚本有两个问题。 如果您知道这些问题的解决方法,请告诉我。非常感谢你抽出时间 JRE检查发生两次,即开始安装和结束安装。我希望JRE检查只在安装开始时进行 我正在检查下面的windows注册表项以检查JRE,但此脚本并非适用于所有情况。我的意思是,对于64位JRE安装,有时这是可行的,有时是失败的。我正在寻找一个逻辑来检查注册表中的所有场景(即32位、64位和所有windows版本) 关于问题1,您应该删除check:InitializeSetup

我正在使用下面的脚本安装一个Java程序。这个脚本有两个问题。 如果您知道这些问题的解决方法,请告诉我。非常感谢你抽出时间

  • JRE检查发生两次,即开始安装和结束安装。我希望JRE检查只在安装开始时进行

  • 我正在检查下面的windows注册表项以检查JRE,但此脚本并非适用于所有情况。我的意思是,对于64位JRE安装,有时这是可行的,有时是失败的。我正在寻找一个逻辑来检查注册表中的所有场景(即32位、64位和所有windows版本)


  • 关于问题1,您应该删除
    check:InitializeSetup来自
    [Run]
    <代码>初始化设置将在安装程序启动时调用一次

    当您添加额外的
    检查时,它会再次触发该功能,这是不必要的

    关于问题2,绝对不应该检测到JRE x64,因为您的安装程序将作为x86执行,并且没有机会访问注册表项的x64部分。要验证x64 JRE,需要设置
    体系结构安装64位模式

    Bitness对于安装程序创建者来说是一个非常复杂的主题,因此您需要进一步研究如何正确使用它。

    为什么InitializeSetup函数在用作检查函数时会被多次调用?

    您正在使用
    InitializeSetup
    事件方法作为
    Check
    函数,是什么导致此方法被多次调用。第一次初始化设置时(作为实际事件方法)和下一次检查确定是否应打开
    [Run]
    部分中的文件条目时

    基本上,对
    检查
    函数使用事件方法是错误的。您甚至不应该手动调用它们,只需让安装程序应用程序启动它们即可。在您的情况下,您可以创建一个只检查JRE是否已安装的函数,并将此函数用于您的
    检查

    如何获取Java SE运行时环境版本?

    您不需要以64位运行安装程序。您只需从WOW注册表节点读取即可获得64位Windows上的64位JRE版本。我会试着用这样的方法:

    [Run]
    Filename: "{app}\MyApp.exe"; Flags: nowait postinstall skipifsilent; Check: IsJREInstalled
    
    [Code]
    #define MinJRE "1.6"
    #define WebJRE "http://www.oracle.com/technetwork/java/javase/downloads/jre6downloads-1902815.html"
    
    function IsJREInstalled: Boolean;
    var
      JREVersion: string;
    begin
      // read JRE version
      Result := RegQueryStringValue(HKLM32, 'Software\JavaSoft\Java Runtime Environment',
        'CurrentVersion', JREVersion);
      // if the previous reading failed and we're on 64-bit Windows, try to read 
      // the JRE version from WOW node
      if not Result and IsWin64 then
        Result := RegQueryStringValue(HKLM64, 'Software\JavaSoft\Java Runtime Environment',
          'CurrentVersion', JREVersion);
      // if the JRE version was read, check if it's at least the minimum one
      if Result then
        Result := CompareStr(JREVersion, '{#MinJRE}') >= 0;
    end;
    
    function InitializeSetup: Boolean;
    var
      ErrorCode: Integer;
    begin
      Result := True;
      // check if JRE is installed; if not, then...
      if not IsJREInstalled then
      begin
        // show a message box and let user to choose if they want to download JRE;
        // if so, go to its download site and exit setup; continue otherwise
        if MsgBox('Java is required. Do you want to download it now ?',
          mbConfirmation, MB_YESNO) = IDYES then
        begin
          Result := False;
          ShellExec('', '{#WebJRE}', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
        end;
      end;
    end;
    

    谢谢你,莱克斯。似乎有一个问题已经解决了,但我还有第二个问题。我认为下面的文件名“{app}\{MyAppExeName}”中的标志不正确;描述:“{cm:LaunchProgram,{#StringChange(MyAppName,&',&&')}”;检查:初始化设置;标志:nowait postinstallskipifsilent@Lex,检查实际上会执行多次(取决于使用检查的部分)。@user2056231,不要使用事件方法进行检查,因为事件方法不用于手动调用。而是创建一个类似
    函数InstallJRE:Boolean的函数
    和该功能分配给
    检查
    。在
    InitializeSetup
    事件方法中,然后简单地像
    Result:=IsJREInstalled那样调用它。这将保留事件方法的含义,因为您以后可能希望扩展当前的
    InitializeSetup
    事件方法,并且您可以忘记,对于特定文件,它也是从
    Check
    调用的。请注意,如果您正在安装64位应用程序,则只应使用64位安装模式。否则,当您需要访问其他注册表时,只需使用适当的标志或常量。永远不要在注册表项中使用
    Wow6432Node
    。(这不仅是糟糕的风格,这个例子在默认情况下实际上不会工作。)当您想要访问64位注册表时,请使用
    HKLM64
    。进一步注意,这个特定的实现将返回32位JRE或64位JRE的版本;如果两者都已安装,则只返回32位版本。这可能不是您想要的,这取决于最终应用程序(或基于Java的组件)实际将如何启动。然而,如果需要的话,颠倒优先顺序是很容易的。
    [Run]
    Filename: "{app}\MyApp.exe"; Flags: nowait postinstall skipifsilent; Check: IsJREInstalled
    
    [Code]
    #define MinJRE "1.6"
    #define WebJRE "http://www.oracle.com/technetwork/java/javase/downloads/jre6downloads-1902815.html"
    
    function IsJREInstalled: Boolean;
    var
      JREVersion: string;
    begin
      // read JRE version
      Result := RegQueryStringValue(HKLM32, 'Software\JavaSoft\Java Runtime Environment',
        'CurrentVersion', JREVersion);
      // if the previous reading failed and we're on 64-bit Windows, try to read 
      // the JRE version from WOW node
      if not Result and IsWin64 then
        Result := RegQueryStringValue(HKLM64, 'Software\JavaSoft\Java Runtime Environment',
          'CurrentVersion', JREVersion);
      // if the JRE version was read, check if it's at least the minimum one
      if Result then
        Result := CompareStr(JREVersion, '{#MinJRE}') >= 0;
    end;
    
    function InitializeSetup: Boolean;
    var
      ErrorCode: Integer;
    begin
      Result := True;
      // check if JRE is installed; if not, then...
      if not IsJREInstalled then
      begin
        // show a message box and let user to choose if they want to download JRE;
        // if so, go to its download site and exit setup; continue otherwise
        if MsgBox('Java is required. Do you want to download it now ?',
          mbConfirmation, MB_YESNO) = IDYES then
        begin
          Result := False;
          ShellExec('', '{#WebJRE}', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
        end;
      end;
    end;