2016-09-28 207 views
1

如何訪問基於Inno Setup的安裝程序的返回代碼?Inno Setup安裝程序測試安裝程序退出代碼

例如,this文檔說如果「安裝程序無法初始化」,則退出代碼將爲1。在我的安裝程序中,在某些情況下,代碼從InitializeSetup()返回False。我在命令提示符下使用/silent標誌運行安裝程序。如果我echo %errorlevel%,我得到的代碼從InitializeSetup()功能0

相關部分:

function InitializeSetup(): Boolean; 
var 
    ResultCode: Integer; 
begin 
    { In silent mode, set Result to false so as to exit before wizard is } 
    { launched in case setup cannot continue. } 
    if WizardSilent() then 
    begin 
    { CompareVersion() logically returns the -1, 0 or 1 based on } 
    { whether the version being installed is less than, equal to or greater } 
    { than version already installed. Returns 0 is there is no existing } 
    { installation. } 
    ResultCode := CompareVersion(); 
    if ResultCode < 0 then 
    begin 
     Result := False; 
     Exit; 
    end; 
    end; 

    Result := True; 
end; 

從命令行,這裏是我正在運行並捕獲返回值:

C:\VersionCheck>myinstaller.exe /Silent 

C:\VersionCheck>echo %errorlevel% 
0 

C:\VersionCheck> 

日誌文件顯示:

2016-09-29 08:05:11.259 Log opened. (Time zone: UTC-07:00) 
2016-09-29 08:05:11.259 Setup version: Inno Setup version 5.5.9 (u) 
2016-09-29 08:05:11.259 Original Setup EXE: C:\VersionCheck\myinstaller.exe 
2016-09-29 08:05:11.259 Setup command line: /SL5="$9051C,3445541,131584,C:\VersionCheck\myinstaller.exe" /Silent 
2016-09-29 08:05:11.259 Windows version: 6.3.9600 (NT platform: Yes) 
2016-09-29 08:05:11.259 64-bit Windows: Yes 
2016-09-29 08:05:11.259 Processor architecture: x64 
2016-09-29 08:05:11.259 User privileges: Administrative 
2016-09-29 08:05:11.259 64-bit install mode: Yes 
2016-09-29 08:05:11.259 Created temporary directory: C:\Users\ADMINI~1\AppData\Local\Temp\2\is-TQB2V.tmp 
2016-09-29 08:05:11.275 Installed version component : 3 
2016-09-29 08:05:11.275 Updating to version component : 0 
2016-09-29 08:05:11.275 This computer already has a more recent version (3.5.0.0) of XYZ. If you wantto downgrade to version 0.0.0.0 then uninstall and try again. Setup will exit. 
2016-09-29 08:05:11.275 InitializeSetup returned False; aborting. 
2016-09-29 08:05:11.275 Got EAbort exception. 
2016-09-29 08:05:11.275 Deinitializing Setup. 
2016-09-29 08:05:11.275 Log closed. 

是否有索姆我錯過了什麼?

+0

是的,你得到的退出代碼1,當您從'InitializeSetup'返回'FALSE'。如果您不這樣做,請向我們展示您用於運行安裝程序的確切命令序列,並檢查退出代碼,包括完整的輸出。 –

+0

@MartinPrikryl - 編輯該問題以獲取更多細節。請檢查。 – Anand

回答

1

您的測試無效。

從命令行執行GUI應用程序(安裝程序)時,控制檯不會等待程序完成。因此%errorlevel%不能包含應用程序(安裝程序)的退出代碼,因爲它尚未完成。

在這種情況下,%errorlevel%反映僅啓動應用程序的錯誤(但不成功)。

另請注意,靜音模式實際上對此沒有影響。非靜音模式的行爲相同。


但是,如果您將完全相同的命令添加到批處理文件(.bat),它將起作用。當批處理文件等待應用程序完成時。

C:\VersionCheck>test.bat 

C:\VersionCheck>myinstaller.exe /Silent 

C:\VersionCheck>echo 1 
1 
C:\VersionCheck> 

test.bat包含您的兩個命令:

myinstaller.exe /Silent 
echo %errorlevel% 
+0

感謝您的快速回答。有用 :) – Anand

相關問題