2013-02-09 191 views
5

我正在使用下面的腳本來安裝Java程序。我正在面對這個腳本的兩個問題。 如果您知道解決這些問題的方法,請讓我知道。我真的很感激你的時間Inno安裝腳本需要幫助 - 檢查jre安裝問題

  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. 

回答

0

關於問題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

位數是安裝程序的創作者一個非常複雜的話題,所以你需要進一步研究如何正確發揮它。

+0

謝謝Lex。看來1個問題已經解決,但我仍然有第二個問題。我認爲這些標誌在下面一行文件名中是不正確的:「{app} \ {#MyAppExeName}」;描述:「{cm:LaunchProgram,{#StringChange(MyAppName,'&','&&')}}"; check:InitializeSetup; Flags:nowait postinstall skipifsilent – Partha 2013-02-09 03:11:10

+0

@Lex,檢查實際上會執行多次(取決於它們所在的部分使用) – TLama 2013-02-09 03:23:31

+1

@ user2056231,不要使用事件方法進行檢查,因爲事件請求並不是手動調用的,而是像'function InstallJRE:Boolean;'這樣的函數賦值給'Check'。 InitializeSetup事件方法就會像調用Result:= IsJREInstalled;這將保留事件方法的含義,因爲您稍後可能想要擴展當前的'InitializeSetup'事件方法,並且您可以忘記它被調用 – TLama 2013-02-09 03:26:32

5

爲什麼InitializeSetup函數在被用作Check函數時被調用多次?

您正在使用InitializeSetup事件方法作爲Check功能,是什麼原因導致這一方法被調用一次以上。第一次初始化設置(作爲真實事件方法)和Check確定的下一次(s)時,是否應該打開[Run]部分中的文件條目。

基本上,使用事件方法的Check函數是錯誤的。你甚至不應該手動調用它們,只需讓它們被安裝程序應用程序解僱。在你的情況,而不是做一個功能,只會檢查是否安裝了JRE,並使用你的Check這樣的功能。

如何獲取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; 
+2

不要在密鑰中使用'Wow6432Node'。 (這不僅是糟糕的風格,這個例子在默認情況下不會工作。)當你想訪問64位註冊表時,使用'HKLM64'。 – Miral 2013-02-09 11:23:09

+0

@病毒,謝謝!固定。 – TLama 2013-02-09 11:35:04

+0

還要注意,這個特定的實現將返回32位JRE或64位JRE的版本;如果兩者均已安裝,則僅返回32位版本。這可能不是你想要的,這取決於最終應用程序(或基於Java的組件)如何實際啓動。然而,如果需要的話,扭轉這個優先順序是微不足道的。 – Miral 2013-02-10 01:23:22