【问题标题】:Need help on Inno Setup script - issue in check the jre install需要有关 Inno Setup 脚本的帮助 - 检查 jre 安装中的问题
【发布时间】:2013-02-09 01:26:33
【问题描述】:

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

  1. JRE 检查发生 2 次,即安装开始和安装结束。我希望 JRE 检查仅在安装开始时进行

  2. 我正在检查以下 Windows 注册表项以检查 JRE,但此脚本不适用于所有情况。我的意思是有时这可以正常工作,有时对于 64 位 JRE 安装会失败。我正在寻找一种逻辑来检查所有场景的注册表(即 32 位、64 位和所有 Windows 版本)

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Test"
#define MyAppVersion "1.0"
#define MyAppPublisher "Test"
#define MyAppURL "gmail.com"
#define MyAppExeName "abc.exe"
#define MinJRE "1.6"


[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
;(To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{200DC169-9647-4295-91B4-B1D1D8482B82}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={userdocs}\xsxsxs\bvb
DisableDirPage=yes
DefaultGroupName=test
DisableProgramGroupPage=yes
AllowNoIcons=yes
LicenseFile=C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\TemsOfUse.txt
OutputDir=C:\test\test
OutputBaseFilename=test
SetupIconFile=C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\Icon\icon.ico
Compression=lzma
SolidCompression=yes
PrivilegesRequired=lowest


[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Dirs]
Name: "{app}\Graphics"
Name: "{app}\lib"
Name: "{app}\Database"
Name: "{app}\Grades"
Name: "{app}\HelpFiles"
Name: "{app}\images"
Name: "{app}\Scripts"

[Files]

Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\test.exe"; DestDir: "{app}"; Flags: ignoreversion;
Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\Graphics\*"; DestDir: "{app}\Graphics"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\lib\*"; DestDir: "{app}\lib"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\DataBase\*"; DestDir: "{app}\DataBase"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\test\Installers_PC_MAC\CORRECTIONS_TO_INSTALLER_BUGS\Grades\*"; DestDir: "{app}\Grades"; Flags: ignoreversion recursesubdirs createallsubdirs


[Icons]
Name: "{group}\test"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:uninstallProgram,test}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}";check:InitializeSetup; Flags: nowait postinstall skipifsilent


[Code]

function installJRE(): Boolean;
   var
   Result1 : Boolean;
   ErrorCode: Integer;
   begin
   Result1 := false;

   Result1 := MsgBox('Java is required to run the program you are trying to install. Please click on Yes button given below to close this installer and be directed to a website were you can download and install Java.',
   mbConfirmation, MB_YESNO) = idYes;
   if Result1 = false then
   begin
   // user can install the Java later also
   Result:=true;
   end else
   begin
   Result:=false;        
   ShellExec('open', 'http://www.oracle.com/technetwork/java/javase/downloads/jre6downloads-1902815.html','','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
  end;
end;


function InitializeSetup(): Boolean;
var 
 jreVersion: String;                            
   begin
   Result := False; 
     if ((RegValueExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\JavaSoft\Java Runtime Environment','CurrentVersion'))) then
     begin      
      RegQueryStringValue(HKLM,'Software\JavaSoft\Java Runtime Environment','CurrentVersion',jreVersion);
      if CompareStr(jreVersion,'{#MinJRE}') > 0 then 
      begin      
          Result:=true;
       end else
       begin
        if(installJRE) then
         Result:=true;  
      end;      
       end else
        if(installJRE) then
        Result:=true;
       end;
    end.

【问题讨论】:

    标签: inno-setup


    【解决方案1】:

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

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

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

    如何获取 Java SE Runtime Environment 版本?

    您无需将设置运行为 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;
    

    【讨论】:

    • 永远不要在密钥中使用Wow6432Node。 (不仅风格不好,而且这个例子在默认情况下实际上不起作用。)当你想访问 64 位注册表时,使用HKLM64
    • 进一步注意,此特定实现将返回 32 位 JRE 或 64 位 JRE 的版本;如果两者都安装了,那么它将只返回 32 位版本。这可能不是您想要的,这取决于最终应用程序(或基于 Java 的组件)实际上将如何启动。但是,如果需要,颠倒优先顺序是微不足道的。
    【解决方案2】:

    关于问题 1,您应该从 [Run] 中删除 check:InitializeSetup;InitializeSetup 将在安装程序启动时调用一次,

    http://www.jrsoftware.org/ishelp/index.php?topic=scriptevents

    当您添加一个额外的check 时,它会再次触发该功能,这是不必要的。

    关于问题 2,根本不应该检测到 JRE x64,因为您的安装程序将作为 x86 执行并且没有机会访问注册表项的 x64 部分。要验证 x64 JRE,您需要设置 ArchitecturesInstallIn64BitMode

    http://www.jrsoftware.org/ishelp/index.php?topic=setup_architecturesinstallin64bitmode

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

    【讨论】:

    • 谢谢莱克斯。似乎第一个问题已解决,但我仍有第二个问题。我认为以下行中的标志不正确 Filename: "{app}\{#MyAppExeName}";说明:“{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}";check:InitializeSetup;标志:nowait postinstall skipifsilent
    • @Lex,检查实际上不止一次执行(取决于使用它们的部分)。
    • @user2056231,不要使用事件方法进行检查,因为事件方法不用于手动调用。而是创建一个类似function InstallJRE: Boolean; 的函数,并将此函数分配给Check。在InitializeSetup 事件方法中,然后像Result := IsJREInstalled; 一样简单地调用它。这将保留事件方法的含义,因为您稍后可能想要扩展当前的 InitializeSetup 事件方法,并且您可能会忘记它也是从 Check 为某个文件调用的。
    • 请注意,如果您正在安装 64 位应用程序,则应仅使用 64 位安装模式。否则,当您需要访问其他注册表时,只需使用适当的标志或常量。
    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    相关资源
    最近更新 更多